ffmpeg_to_webm_2pass.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. ### set USAGE message
  3. MESSAGE=$'USAGE: ffmpeg_to_webm <resolution> <constant rate factor (crf)>\nExample: ffmpeg_to_webm 640:-1 31'
  4. # check and set parameters
  5. if [ -z "$1" ]; then
  6. echo "$MESSAGE"
  7. exit 1
  8. fi
  9. if [ -z "$2" ]; then
  10. echo "$MESSAGE"
  11. exit 1
  12. fi
  13. # show entered parameters
  14. echo Resolution: "$1"
  15. RESOLUTION="$1"
  16. echo Constant Rate Factor: "$2"
  17. CRF="$2"
  18. echo Passes: 2pass encoding
  19. # timeout confirmation
  20. echo converting all files in $(pwd)
  21. echo 10 seconds to cancel...
  22. echo -----------------------
  23. sleep 10s
  24. # convert every file in dir
  25. for FILE in *{.mp4,h264,mkv,avi}
  26. do
  27. [ -e "$FILE" ] || continue
  28. echo "##########"
  29. echo Converting "$FILE" to WEBM container :: -c:v libvpx-vp9 :: -c:a libopus
  30. echo "##########"
  31. #first pass
  32. echo "Y" | ffmpeg -i "$FILE" -vf scale="$RESOLUTION" -c:v libvpx-vp9 -pass 1 -b:v 0 -crf "$CRF" -threads 8 -speed 4 -tile-columns 6 -frame-parallel 1 -an -f webm /dev/null
  33. #second pass
  34. echo "Y" | ffmpeg -i "$FILE" -vf scale="$RESOLUTION" -c:v libvpx-vp9 -pass 2 -b:v 0 -crf "$CRF" -threads 8 -speed 2 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 -c:a libopus -b:a 64k -f webm "${FILE%.*}".webm
  35. echo Conversion of "$FILE" successful!
  36. #Remove or comment out this line if you want to keep mp4 files
  37. #rm "$FILE";
  38. done