Advertisement
constantin-net

mpv_webm_v02

Aug 8th, 2019 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.18 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. start_time=""
  4. length=""
  5. amap=""
  6. output_path=""
  7. height=""
  8. param="-vcodec libvpx -qmin 20 -qmax 30 -acodec libvorbis -b:v 1M -b:a 128k -crf 30 -cpu-used 2 -threads 2"
  9.  
  10. if [[ -z "$1" ]]; then
  11.     printf "usage: video subs [audio [output [height]]]\n"
  12.     exit
  13. fi
  14.  
  15. rm -f /tmp/working_video
  16. ln -s "`pwd`/$1" /tmp/working_video
  17.  
  18. #audio
  19. if [[ -n "$3" ]]; then
  20.     if [[  "$3" == "no" ]]; then
  21.         amap="-an"
  22.     else
  23.         internal_alang=$(echo "$3" | sed s/[^0-9]//g)
  24.         let "selected_alang=$internal_alang-1"
  25.         amap="-map 0:a:$selected_alang"
  26.     fi
  27. else
  28.     amap="-map 0:a:0";
  29.     #amap="";
  30. fi
  31.  
  32. #output
  33. if [[ -n "$4" ]]; then
  34.     output_path="$4"
  35. else
  36.     output_path="$HOME";
  37. fi
  38.  
  39. if [ -f /tmp/webm_start ]; then
  40.     start_time_var=`cat /tmp/webm_start`;
  41.     start_time="-ss $start_time_var";
  42. else
  43.     start_time="-ss 0";
  44. fi
  45.  
  46. if [ -f /tmp/webm_end ]; then
  47.     length_var=$(echo "`cat /tmp/webm_end` - $start_time_var" | bc);
  48.     length="-t $length_var";
  49. else
  50.     length="";
  51. fi
  52. if [[ -n "$2" && "$2" != "no" ]]; then #with subs
  53.     if [[ -n "$5" ]]; then
  54.         height=";[v]scale=trunc(oh*a/2)*2:$5[v]"
  55.     fi
  56.     slang=`echo "$2" | awk -F ' ' '{print $2}'`
  57.     if [[ ${slang} == "unknown" ]]; then
  58.         external_subs=`echo "$2" | sed 's/.*\(\"[^)()].*\"\).*/\1/g'`
  59.         rm -f /tmp/working_subs
  60.         ln -s "`pwd`/`echo ${external_subs%?} | cut -c 2-`" /tmp/working_subs
  61.         subs="-filter_complex [0:v:0]subtitles=/tmp/working_subs[v]$height -map [v]"
  62.     else
  63.         internal_subs=`echo "$2" | sed s/[^0-9]//g`
  64.         let "selected_subs=$internal_subs-1"
  65.         subs="-filter_complex [0:v:0]subtitles=/tmp/working_video:si=$selected_subs[v]$height -map [v]"
  66.     fi
  67.     ffmpeg -i "$1" $start_time $subs $amap $param $length -async 1 $output_path/"$1 s $start_time_var l $length_var".webm
  68. else #without subs
  69.     if [[ -n "$5" ]]; then
  70.         height="-vf scale=trunc(oh*a/2)*2:$5"
  71.     fi
  72.     subs="-sn -map 0:v:0";
  73.     ffmpeg $start_time $length -i "$1" $subs $amap $param $height -async 1 $output_path/"$1 s $start_time_var l $length_var".webm
  74. fi
  75.  
  76. rm -f /tmp/working_video
  77. rm -f /tmp/working_subs
  78.  
  79. sleep 1
  80. exit
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement