Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- start_time=""
- length=""
- amap=""
- output_path=""
- height=""
- param="-vcodec libvpx -qmin 20 -qmax 30 -acodec libvorbis -b:v 1M -b:a 128k -crf 30 -cpu-used 2 -threads 2"
- if [[ -z "$1" ]]; then
- printf "usage: video subs [audio [output [height]]]\n"
- exit
- fi
- rm -f /tmp/working_video
- ln -s "`pwd`/$1" /tmp/working_video
- #audio
- if [[ -n "$3" ]]; then
- if [[ "$3" == "no" ]]; then
- amap="-an"
- else
- internal_alang=$(echo "$3" | sed s/[^0-9]//g)
- let "selected_alang=$internal_alang-1"
- amap="-map 0:a:$selected_alang"
- fi
- else
- amap="-map 0:a:0";
- #amap="";
- fi
- #output
- if [[ -n "$4" ]]; then
- output_path="$4"
- else
- output_path="$HOME";
- fi
- if [ -f /tmp/webm_start ]; then
- start_time_var=`cat /tmp/webm_start`;
- start_time="-ss $start_time_var";
- else
- start_time="-ss 0";
- fi
- if [ -f /tmp/webm_end ]; then
- length_var=$(echo "`cat /tmp/webm_end` - $start_time_var" | bc);
- length="-t $length_var";
- else
- length="";
- fi
- if [[ -n "$2" && "$2" != "no" ]]; then #with subs
- if [[ -n "$5" ]]; then
- height=";[v]scale=trunc(oh*a/2)*2:$5[v]"
- fi
- slang=`echo "$2" | awk -F ' ' '{print $2}'`
- if [[ ${slang} == "unknown" ]]; then
- external_subs=`echo "$2" | sed 's/.*\(\"[^)()].*\"\).*/\1/g'`
- rm -f /tmp/working_subs
- ln -s "`pwd`/`echo ${external_subs%?} | cut -c 2-`" /tmp/working_subs
- subs="-filter_complex [0:v:0]subtitles=/tmp/working_subs[v]$height -map [v]"
- else
- internal_subs=`echo "$2" | sed s/[^0-9]//g`
- let "selected_subs=$internal_subs-1"
- subs="-filter_complex [0:v:0]subtitles=/tmp/working_video:si=$selected_subs[v]$height -map [v]"
- fi
- ffmpeg -i "$1" $start_time $subs $amap $param $length -async 1 $output_path/"$1 s $start_time_var l $length_var".webm
- else #without subs
- if [[ -n "$5" ]]; then
- height="-vf scale=trunc(oh*a/2)*2:$5"
- fi
- subs="-sn -map 0:v:0";
- ffmpeg $start_time $length -i "$1" $subs $amap $param $height -async 1 $output_path/"$1 s $start_time_var l $length_var".webm
- fi
- rm -f /tmp/working_video
- rm -f /tmp/working_subs
- sleep 1
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement