Advertisement
constantin-net

mpv_mp4cut_v02

Sep 29th, 2023
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. height=""
  4. length=""
  5. start_time=""
  6. aparam=""
  7.  
  8. if [[ -z "$1" ]]; then
  9.     printf "usage: video [audio [output [height]]]\n"
  10.     exit
  11. fi
  12.  
  13. #audio
  14. if [[ -n "$2" ]]; then
  15.     if [[  "$2" == "no" ]]; then
  16.         aparam="-an"
  17.     else
  18.         internal_alang=$(echo "$2" | sed s/[^0-9]//g)
  19.         let "selected_alang=$internal_alang-1"
  20.         aparam="-map 0:v:0 -map 0:a:$selected_alang -acodec copy"
  21.     fi
  22. else
  23.     aparam="-acodec copy"
  24. fi
  25.  
  26. #output
  27. if [[ -n "$3" ]]; then
  28.     output_path="$3"
  29. else
  30.     output_path="$HOME";
  31. fi
  32.  
  33. #height
  34. if [[ -n "$4" ]]; then
  35.     height="-vf scale=trunc(oh*a/2)*2:$4"
  36. else
  37.     height=""
  38. fi
  39.  
  40. if [[ -n `ls /tmp/webm_start` ]]; then
  41.     start_time_var=`cat /tmp/webm_start`
  42.     start_time="-ss $start_time_var"
  43. else
  44.     start_time="-ss 0";
  45. fi
  46.  
  47. if [[ -n `ls /tmp/webm_end` ]]; then
  48.     length_var=$(echo "`cat /tmp/webm_end` - $start_time_var" | bc)
  49.     length="-t $length_var"
  50. else
  51.     length=""
  52. fi
  53.  
  54. ffmpeg $start_time $length -i "$1" -vcodec copy $aparam -f mp4 $height -sn -cpu-used 2 -threads 2 $output_path/"$1 s $start_time_var l $length_var".mp4
  55. sleep 1
  56. exit
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement