Advertisement
Guest User

Optimize your webms

a guest
Jun 28th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.92 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $1)
  4.     echo "duration: $duration"
  5.  
  6. fps=$( ffprobe -v 0 -of compact=p=0 -select_streams 0 -show_entries stream=r_frame_rate $1 | sed 's/r_frame_rate=//' | bc )
  7.     echo "fps: $fps"
  8.  
  9. TotalFrames=$( bc <<< "$duration*$fps" )
  10.     echo "Total Frames: $TotalFrames"
  11.  
  12. clipsCount=20
  13.  
  14. clipsLength=40
  15.  
  16. for i in $( seq 0 $( bc <<< "$clipsCount-1" ) ); do \
  17.     skipFrames=$( bc <<< "$i*($TotalFrames/$clipsCount)" )
  18.     skipTime=$( bc <<< "$skipFrames/$fps" )
  19.     ffmpeg -ss $skipTime -i $1 -map 0:v:0 -map 0:a -vframes $clipsLength \
  20.         -c:v vp9 -crf 30 -b:v 0k -pix_fmt yuv420p \
  21.         -c:a libvorbis -q:a 5 \
  22.         -y -cpu-used 8 -threads 8 -speed 5 $i-50frames.webm
  23. done
  24.  
  25. rm ./scr_files.txt
  26.  
  27. ls | grep webm | sort -h | while read a; do echo "file '$a'" >> ./scr_files.txt; done
  28.  
  29. ffmpeg -f concat -i ./scr_files.txt -c copy result.webm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement