Advertisement
constantin-net

mpv_crop_v02

Jul 2nd, 2019 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.61 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. height=""
  4. length=""
  5. start_time=""
  6. amap=""
  7. crop1=""
  8. crop2=""
  9. param="-vcodec libvpx -qmin 20 -qmax 30 -acodec libvorbis -b:v 1M -b:a 128k -crf 30 -cpu-used 2 -threads 2"
  10.  
  11. if [[ -z "$1" ]]; then
  12.     printf "usage: video [audio [output [height]]]\n"
  13.     exit
  14. fi
  15.  
  16. #audio
  17. if [[ -n "$2" ]]; then
  18.     if [[  "$2" == "no" ]]; then
  19.         amap="-an"
  20.     else
  21.         internal_alang=$(echo "$2" | sed s/[^0-9]//g)
  22.         let "selected_alang=$internal_alang-1"
  23.         amap="-map 0:a:$selected_alang"
  24.     fi
  25. else
  26.     amap="-map 0:a:0";
  27.     #amap="";
  28. fi
  29.  
  30. #output
  31. if [[ -n "$3" ]]; then
  32.     output_path="$3"
  33. else
  34.     output_path="$HOME";
  35. fi
  36.  
  37. #height
  38. if [[ -n "$4" ]]; then
  39.     height="-vf scale=trunc(oh*a/2)*2:$4"
  40. else
  41.     height="";
  42. fi
  43.  
  44. if [[ -n `ls /tmp/webm_start` ]]; then
  45.     start_time_var=`cat /tmp/webm_start`;
  46.     start_time="-ss $start_time_var";
  47. else
  48.     start_time="-ss 0";
  49. fi
  50.  
  51. if [[ -n `ls /tmp/webm_end` ]]; then
  52.     length_var=$(echo "`cat /tmp/webm_end` - $start_time_var" | bc);
  53.     length="-t $length_var";
  54. else
  55.     length="";
  56. fi
  57.  
  58. if [[ -n `ls /tmp/webm_crop1` ]]; then
  59.     crop1=`cat /tmp/webm_crop1`
  60. else
  61.     crop1="0:0";
  62. fi
  63.  
  64. x1="${crop1%:*}"
  65. y1="${crop1#*:}"
  66.  
  67. if [[ -n `ls /tmp/webm_crop2` ]]; then
  68.     crop2=`cat /tmp/webm_crop2`
  69.     x2="${crop2%:*}"
  70.     y2="${crop2#*:}"
  71.     w=$(echo "$x2 - $x1" | bc)
  72.     h=$(echo "$y2 - $y1" | bc)
  73. else
  74.     w="100"
  75.     h="100"
  76. fi
  77.  
  78. 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
  79. sleep 1
  80. exit
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement