transcode 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. sep="
  3. ###########################
  4. "
  5. # videoblerg.wordpress.com/2017/11/10/ffmpeg-and-how-to-use-it-wrong/comment-page-1/
  6. file="$1"
  7. vcodec=x264
  8. pix_fmt=yuv420p
  9. vbitrate=500
  10. #################################
  11. preset=veryslow
  12. # presets: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow
  13. tune=film
  14. # tunes: film,animation, grain, stillimage, psnr, ssim, fastdecode, zerolatency
  15. bufsize=$((vbitrate))
  16. maxrate=$((vbitrate + vbitrate/3))
  17. ffmpeg_cmd="ffmpeg -nostdin -hide_banner -analyzeduration 2147483647 -probesize 2147483647"
  18. endopts="-max_muxing_queue_size 9999"
  19. outfile="${file%.*}.$vcodec.$pix_fmt.v$vbitrate.$preset.$tune.mp4"
  20. fix="${file%.*}.fix.mkv"
  21. cleanup() {
  22. rm ffmpeg2pass-0.log*
  23. rm "$fix"
  24. }
  25. trap cleanup EXIT
  26. cmd=( $ffmpeg_cmd -i "$file" -r 10 -c:v ffvhuff -an $endopts "$fix" )
  27. echo "$sep${cmd[@]}$sep"
  28. "${cmd[@]}"
  29. cmd=( $ffmpeg_cmd -i "$fix" -r 10 -pix_fmt "$pix_fmt" -vsync 1 -vcodec lib$vcodec -b:v: ${vbitrate}k -bufsize ${bufsize}k -maxrate ${maxrate}k -preset $preset -profile:v high -tune $tune -pass 1 -an $endopts -f mp4 -y /dev/null )
  30. echo "$sep${cmd[@]}$sep"
  31. "${cmd[@]}"
  32. cmd=( $ffmpeg_cmd -i "$fix" -r 10 -pix_fmt "$pix_fmt" -vsync 1 -vcodec lib$vcodec -b:v: ${vbitrate}k -bufsize ${bufsize}k -maxrate ${maxrate}k -preset $preset -profile:v high -tune $tune -pass 2 -an $endopts -f mp4 "$outfile" )
  33. echo "$sep${cmd[@]}$sep"
  34. "${cmd[@]}"