Braingame

Simple script to slice videos into webms

Apr 25th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.99 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Path to the directory with the input videos
  4. folder="./to_convert"
  5. # Quantity of webms to produce for each input video
  6. quantity=6
  7. # Length of each webm (in seconds)
  8. interval=10
  9. # Whether you want audio or not
  10. audio=true
  11.  
  12. if [[ "$audio" = true ]]; then
  13.     audio_bitrate=96
  14.     audio_settings="-c:a libvorbis -ac 2 -b:a ${audio_bitrate}K"
  15. else
  16.     audio_bitrate=0
  17.     audio_settings="-an"
  18. fi
  19.  
  20. # Change 4 to whatever file size limit you have (in MB)
  21. video_bitrate=$(bc <<< 4*1000*8/$interval-$audio_bitrate)
  22.  
  23. # Change into the video folder
  24. cd "$folder" || exit
  25. # Create sub-directory for all produced webms
  26. mkdir ../done 2> /dev/null
  27.  
  28. for input in *; do (
  29.     # Where to start the first webm (in seconds)
  30.     start=0
  31.     for (( i = 1; i <= quantity; i++ ))
  32.     do
  33.         ffmpeg -y -hide_banner -ss $start -i "$input" -t $interval -c:v libvpx -crf 10 -qmax 50 -b:v ${video_bitrate}K -deadline good -cpu-used 0 $audio_settings "../done/${input%.*}_${i}.webm"
  34.         (( start+=interval ))
  35.     done
  36. ); done
Add Comment
Please, Sign In to add comment