ffmpeg_to_webm_1pass.sh 1019 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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: 1pass 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 -b:v 0 -crf "$CRF" -c:a libopus -b:a 64k -f webm "${FILE%.*}".webm
  33. echo Conversion of "$FILE" successful!
  34. #Remove or comment out this line if you want to keep mp4 files
  35. #rm "$FILE";
  36. done