McModder

Ultimate FFMPEG h.265 script

Dec 1st, 2020 (edited)
844
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. CRF="${CRF:-23}"
  3. BITRATE="${BITRATE:-96k}"
  4. SUB_CHARSET="${SUB_CHARSET:-cp1251}"
  5. SUB_LANG="${SUB_LANG:-rus}"
  6. SUB_FORMAT="${SUB_FORMAT:-mov_text}"
  7. VID_FORMAT="${VID_FORMAT:-mp4}"
  8. PARAMS="$PARAMS"
  9.  
  10. TELEGRAM() {
  11.     [ -z "${TG_TOKEN:+x}" ] && echo "$1" && return 0
  12.     curl -sL -G --data-urlencode "token=$TG_TOKEN" --data-urlencode "text=$1" https://ewh.mcmodder.ru/send.php 2>&1 >/dev/null
  13. }
  14.  
  15. CONVERT_SUBS() {
  16.     ffmpeg -i "$1" -sub_charenc "$SUB_CHARSET" -i "${1%.*}.srt" -metadata:s:1 "language=$SUB_LANG" -map 0:v -map 0:a -map 0:s\? -map 1:s\? -c:v libx265 -crf $CRF -c:a libopus -b:a $BITRATE -c:s "$SUB_FORMAT" -ac 2 $PARAMS "out/${1%.*}.$VID_FORMAT"
  17. }
  18.  
  19. CONVERT() {
  20.     ffmpeg -i "$1" -map 0:v -map 0:a -map 0:s\? -c:v libx265 -crf $CRF -c:a libopus -b:a $BITRATE -c:s copy -ac 2 $PARAMS "out/${1%.*}.$VID_FORMAT"
  21. }
  22.  
  23. GETSIZE() {
  24.     du -h "$1" | cut -f1
  25. }
  26.  
  27. TELEGRAM "Started"
  28. mkdir out
  29. for videofile in "$@"; do
  30.     if [ -f "${videofile%.*}.srt" ]; then
  31.         CONVERT_SUBS "$videofile"
  32.     else
  33.         CONVERT "$videofile"
  34.     fi
  35.     TELEGRAM "Converted \`$videofile\` from *$(GETSIZE "$videofile")* to *$(GETSIZE "out/${videofile%.*}.$VID_FORMAT")*"
  36. done
  37. TELEGRAM "All done!"
  38.  
RAW Paste Data