GegoXaren

enc2firefox.sh

Mar 10th, 2020 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.99 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. ###################
  3. # FILE NAME: enc2firefox.sh
  4. #
  5. # Encodes (mp4/x264) videos so they can be played in firefox.
  6. #
  7. # Updates:
  8. # 2020-09-05:
  9. #   * Removed an eval that made no sense.
  10. #   * Added FJ mode for those spicy memes.
  11. #
  12. # 2021-01-13:
  13. #   * Fixed up if statments
  14. #
  15. ####################
  16. ARGS=()
  17. ARGS="${@}"
  18.  
  19. __IN_NAME=
  20. __OUT_NAME=
  21. __USE_WEBM=false
  22. __USE_FJ=false
  23.  
  24. __help () {
  25.   echo "enc2firefox.sh -- Make Videos Playable in Firefox"
  26.   echo " "
  27.   echo "-i <input video file>     Input Video File."
  28.   echo " "
  29.   echo "-o <output video file>    Output Video File"
  30.   echo "                          (.mp4 will be added to the end)."
  31.   echo " "
  32.   echo "-m                        output webm instead"
  33.   echo "                          (Will change ending to .webm)."
  34.   echo " "
  35.   echo "-f                        Use FJ settings. Low bandwith, small size."
  36.   echo "                          (Will append .mp4 to the end)."
  37.   echo " "
  38.   exit
  39. }
  40.  
  41. __enc_mp4 () {
  42.   ffmpeg -i "$__IN_NAME"\
  43.             -c:v libx264\
  44.             -preset slower\
  45.             -crf 22\
  46.             -pix_fmt yuv420p\
  47.             -c:a aac\
  48.             -b:a 128k\
  49.             "$__OUT_NAME".mp4
  50. }
  51.  
  52. __enc_fj () {
  53.   ffmpeg -i "$__IN_NAME"\
  54.             -c:v libx264\
  55.             -preset slower\
  56.             -pix_fmt yuv420p\
  57.             -b:v 1024k\
  58.             -s hd720\
  59.             -r 30\
  60.             -c:a aac\
  61.             -b:a 128k\
  62.             "$__OUT_NAME".mp4
  63. }
  64.  
  65. __enc_webm () {
  66.   ffmpeg -i "$__IN_NAME"\
  67.             -c:v libvpx-vp9\
  68.             -b:v 0\
  69.             -crf 20\
  70.             -c:a libopus\
  71.             "$__OUT_NAME".webm
  72. }
  73.  
  74. __parse_args() {
  75.   if [[ -z "$1" ]]
  76.   then
  77.     echo "Try --help or -h."
  78.     exit 1
  79.   fi
  80.  
  81.  
  82.   while [[ $# -gt 0 ]]
  83.   do
  84.    
  85.     case "${1}" in
  86.       -i)
  87.       __IN_NAME="$2"
  88.       shift
  89.       shift
  90.       ;;
  91.       -o)
  92.       __OUT_NAME="$2"
  93.       shift
  94.       shift
  95.       ;;
  96.       -m)
  97.       __USE_WEBM=true
  98.       shift
  99.       ;;
  100.       -f)
  101.       __USE_FJ=true
  102.       shift
  103.       ;;
  104.       -h|--help)
  105.       __help
  106.       shift
  107.       ;;
  108.       *)
  109.       __help
  110.       exit 1
  111.       shift
  112.       ;;
  113.       --)
  114.       shift
  115.       break
  116.       ;;
  117.     esac
  118.   done
  119. }
  120.  
  121. __main () {
  122.   if [[ ! -e "$__IN_NAME" ]]
  123.   then
  124.     echo "missing input audio. Please provide."
  125.     exit 1
  126.   fi
  127.  
  128.   if [[ $__OUT_NAME == "" ]]
  129.   then
  130.     echo "missing output file name. Please provide."
  131.     exit 1
  132.   fi
  133.  
  134.  
  135.   if [[ $__USE_WEBM == true ]]
  136.   then
  137.     if [[ $__IN_NAME == $__OUT_NAME.webm ]]
  138.     then
  139.       echo "Filenames can't be the same."
  140.       exit
  141.     fi
  142.     __enc_webm
  143.   elif [[ $__USE_FJ == true ]]
  144.   then
  145.     if [[ $__IN_NAME == $__OUT_NAME.mp4 ]]
  146.     then
  147.       echo "Filenames can't be the same."
  148.       exit
  149.     fi
  150.     __enc_fj
  151.   else
  152.     if [[ $__IN_NAME == $__OUT_NAME.mp4 ]]
  153.     then
  154.       echo "Filenames can't be the same."
  155.       exit
  156.     fi
  157.     __enc_mp4
  158.   fi
  159. }
  160.  
  161. __parse_args "${@}"
  162. __main
Add Comment
Please, Sign In to add comment