Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- height=""
- length=""
- start_time=""
- amap=""
- crop1=""
- crop2=""
- 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 [audio [output [height]]]\n"
- exit
- fi
- #audio
- if [[ -n "$2" ]]; then
- if [[ "$2" == "no" ]]; then
- amap="-an"
- else
- internal_alang=$(echo "$2" | 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 "$3" ]]; then
- output_path="$3"
- else
- output_path="$HOME";
- fi
- #height
- if [[ -n "$4" ]]; then
- height="-vf scale=trunc(oh*a/2)*2:$4"
- else
- height="";
- fi
- if [[ -n `ls /tmp/webm_start` ]]; then
- start_time_var=`cat /tmp/webm_start`;
- start_time="-ss $start_time_var";
- else
- start_time="-ss 0";
- fi
- if [[ -n `ls /tmp/webm_end` ]]; then
- length_var=$(echo "`cat /tmp/webm_end` - $start_time_var" | bc);
- length="-t $length_var";
- else
- length="";
- fi
- if [[ -n `ls /tmp/webm_crop1` ]]; then
- crop1=`cat /tmp/webm_crop1`
- else
- crop1="0:0";
- fi
- x1="${crop1%:*}"
- y1="${crop1#*:}"
- if [[ -n `ls /tmp/webm_crop2` ]]; then
- crop2=`cat /tmp/webm_crop2`
- x2="${crop2%:*}"
- y2="${crop2#*:}"
- w=$(echo "$x2 - $x1" | bc)
- h=$(echo "$y2 - $y1" | bc)
- else
- w="100"
- h="100"
- fi
- ffmpeg $start_time $length -i "$1" -map 0:v:0 $amap -vf "crop=$w:$h:$crop1" $height $param -sn $output_path/"$1 s $start_time_var l $length_var cropped w$w h$h".webm
- sleep 1
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement