Advertisement
Braingame

Simple script to slice mp4 into webms

Apr 24th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.77 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Quantity of webms to produce for each input video
  4. quantity=6
  5. # Length of each webm (in seconds)
  6. interval=10
  7. # Whether you want audio or not
  8. audio=true
  9.  
  10. if [[ "$audio" = true ]]; then
  11.     audio_bitrate=96
  12.     audio_settings="-c:a libvorbis -b:a ${audio_bitrate}K"
  13. else
  14.     audio_bitrate=0
  15.     audio_settings="-an"
  16. fi
  17.  
  18. # Change 4 to whatever file size limit you have (in MB)
  19. video_bitrate=$(bc <<< 4*1000*8/$interval-$audio_bitrate)
  20.  
  21. for input in *.mp4; do (
  22.     # Where to start the first webm (in seconds)
  23.     start=0
  24.     for (( i = 1; i <= quantity; i++ ))
  25.     do
  26.         ffmpeg -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 "${input%.*}_${i}.webm"
  27.         (( start+=interval ))
  28.     done
  29. ); done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement