ffmpeg_to_theora_1pass.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. ### set USAGE message
  3. MESSAGE=$'USAGE: ffmpeg_to_webm <resolution> <minrate> <bitrate> <maxrate>\nExample: ffmpeg_to_webm 640:-1 500k 3000k 5500k'
  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. if [ -z "$3" ]; then
  14. echo "$MESSAGE"
  15. exit 1
  16. fi
  17. if [ -z "$4" ]; then
  18. echo "$MESSAGE"
  19. exit 1
  20. fi
  21. # show entered parameters
  22. echo Resolution: "$1"
  23. RESOLUTION="$1"
  24. echo Minrate: "$2"
  25. MINRATE="$2"
  26. echo Bitrate: "$3"
  27. BITRATE="$3"
  28. echo Maxrate: "$4"
  29. maxRATE="$4"
  30. echo Passes: 1pass encoding
  31. # timeout confirmation
  32. echo converting all files in $(pwd)
  33. echo 10 seconds to cancel...
  34. echo -----------------------
  35. sleep 10s
  36. # convert every file in dir
  37. for FILE in *{.mp4,h264,mkv,avi}
  38. do
  39. [ -e "$FILE" ] || continue
  40. echo "##########"
  41. echo Converting "$FILE" to MKV container :: -c:v libtheora :: -codec:a libvorbis
  42. echo "##########"
  43. #first pass
  44. #echo ffmpeg -i "$FILE" -map 0:0 -map 0:1 -map 0:4 -map 0:7 -map 0:8 -map 0:9 -map 0:10 -map 0:11 -map 0:12 -vf scale="$RESOLUTION" -c:v libtheora -minrate "$MINRATE" -b:v "$BITRATE" -maxrate "$MAXRATE" -codec:a libvorbis -b:a 128k "${FILE%.*}"_encode.mkv
  45. echo "Y" | ffmpeg -i "$FILE" -vf scale="$RESOLUTION" -c:v libtheora -minrate "$MINRATE" -b:v "$BITRATE" -maxrate "$MAXRATE" -codec:a libvorbis -b:a 128k "${FILE%.*}"_encode.mkv
  46. echo Conversion of "$FILE" successful!
  47. #Remove or comment out this line if you want to keep mp4 files
  48. #rm "$FILE";
  49. done