2-pass ratecontrol in FFmpeg

2-pass ratecontrol in FFmpeg

I want to use 2pass ratecontrol in 2nd pass mode in FFmpeg but I don't know the proper command. I've seen these been used -flags, -input_preserved and -pass2 in ffmpeg documentation but I don't how to use them (If I need to use these anyway). Any ideas?

答案1

I'll assume you're using libx264 to encode H.264 video. The most basic command is something like:

ffmpeg -i input -c:v libx264 -b:v 800k -pass 1 output.mp4
ffmpeg -i input -c:v libx264 -b:v 800k -pass 2 output.mp4

However, it can be improved:

ffmpeg -y -i input -c:v libx264 -preset medium -b:v 800k -an -pass 1 -f mp4 /dev/null
ffmpeg -y -i input -c:v libx264 -preset medium -b:v 800k -c:a aac -b:a 128k -pass 2 -movflags +faststart output.mp4
  • The audio should not need to be encoded for the first pass, so -an is added to the first pass command.

  • The first pass does not need to output a video file, so it is directed to /dev/null/. Windows users can use NUL instead.

  • 2-passes with libx264 is usually used if you are targeting a specific output file size (file size = bitrate * duration). If this is not the utmost concern to you then just use a single pass with -crf instead.

  • Use the slowest -preset you have patience for.

  • See FFmpeg Wiki: H.264 Video Encoding Guide for more info including how to get the file size you want.

相关内容