Advertisement
GegoXaren

video2lbry.sh

Mar 16th, 2020 (edited)
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.91 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. ###################
  3. # FILE NAME: video2lbry.sh
  4. #
  5. # Encodes videos so they are ready to be uploaded to LBRY.
  6. #
  7. # Changes
  8. # 2021-01-13
  9. #   * fixed up if statments
  10. #   * removed eval
  11. #
  12. ####################
  13. ARGS=()
  14. ARGS="${@}"
  15.  
  16. __IN_NAME=
  17. __OUT_NAME=
  18.  
  19. __help () {
  20.   echo "video2lbry.sh -- Make vide ready for upload to LBRY."
  21.   echo " "
  22.   echo "-i <input video file>     Input Video File."
  23.   echo " "
  24.   echo "-o <output video file>    Output Video File"
  25.   echo "                          (_lbry.mp4 will be added to the end)."
  26.   echo " "
  27. }
  28.  
  29. __enc_mp4 () {
  30.   ffmpeg -y -i "$__IN_NAME"\
  31.           -threads 7\
  32.           -c:v libx264\
  33.           -crf 21\
  34.           -preset slower\
  35.           -pix_fmt yuv420p\
  36.           -maxrate 5000K\
  37.           -bufsize 5000K\
  38.           -vf 'scale=if(gte(iw\,ih)\,min(2560\,iw)\,-2):if(lt(iw\,ih)\,min(2560\,ih)\,-2)'\
  39.           -movflags +faststart\
  40.           -c:a aac\
  41.           -b:a 256k\
  42.           "${__OUT_NAME}_lbry.mp4"
  43. }
  44.  
  45. __parse_args() {
  46.   if [[ -z "$1" ]]
  47.   then
  48.     echo "Try --help or -h."
  49.     exit 1
  50.   fi
  51.  
  52.  
  53.   while [[ $# -gt 0 ]]
  54.   do
  55.    
  56.     case "${1}" in
  57.       -i)
  58.       __IN_NAME="$2"
  59.       shift
  60.       shift
  61.       ;;
  62.       -o)
  63.       __OUT_NAME="$2"
  64.       shift
  65.       shift
  66.       ;;
  67.       -m)
  68.       __USE_WEBM=true
  69.       shift
  70.       ;;
  71.       -h|--help)
  72.       __help
  73.       shift
  74.       ;;
  75.       *)
  76.       __help
  77.       exit
  78.       shift
  79.       ;;
  80.       --)
  81.       shift
  82.       break
  83.       ;;
  84.     esac
  85.   done
  86. }
  87.  
  88. __main () {
  89.   if [[ ! -e "$__IN_NAME" ]]
  90.   then
  91.     echo "missing input audio. Please provide."
  92.     exit 1
  93.   fi
  94.  
  95.   if [[ $__OUT_NAME == "" ]]
  96.   then
  97.     echo "missing output file name. Please provide."
  98.     exit 1
  99.   fi
  100.  
  101.  
  102.   if [[ $__IN_NAME == ${__OUT_NAME}_lbry.mp4 ]]
  103.   then
  104.     echo "Filenames can't be the same."
  105.     exit
  106.   fi
  107.   __enc_mp4
  108. }
  109.  
  110. __parse_args "${@}"
  111. __main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement