0

I am trying to save some videos in specific bitrate (8000k) and for this, I used the following code:

ffmpeg  -i  input_1080p60  -c:v  libx264 -pix_fmt yuv420p  -b:v 8000K -bufsize 8000K -minrate 8000K -maxrate 8000K -x264opts keyint=120:min-keyint=120 -preset veryfast -profile:v high out_1080p.264

but after saving the videos, I find out each video has a different bitrate except 8000k ( for example 5000k, 6000k, 7500k,...). but I define the minrate 8000k. do you know what is the problem and how can I force the above code to have the specific bitrate? Thank you.

david
  • 1,255
  • 4
  • 13
  • 26

1 Answers1

1

That's what 2-pass encoding is for. See FFmpeg Wiki

The idea behind 2-pass encoding is that by running FFmpeg twice it can first analyze the video to decide how to best allocate the bits to meet the specific bitrate then the second pass does the actual encoding.

So your command should be modified like this:

ffmpeg -i  input_1080p60 \
  -pass 1 \
  -c:v  libx264 -pix_fmt yuv420p -b:v 8000K -bufsize 8000K \
  -x264opts keyint=120:min-keyint=120 \
  -preset veryfast -profile:v high /dev/null

ffmpeg -i input_1080p60 \
  -pass 2 \
  -c:v  libx264 -pix_fmt yuv420p -b:v 8000K -bufsize 8000K \
  -x264opts keyint=120:min-keyint=120 \
  -preset veryfast -profile:v high out_1080p.264

If you are in Windows, use NUL instead of /dev/null.

kesh
  • 4,515
  • 2
  • 12
  • 20
  • what does it mean? I am a beginner at video processing. Does this mean I cannot do it and save videos in a specific bitrate? – david May 14 '22 at 13:42
  • Let me expand on it – kesh May 14 '22 at 14:17
  • It's a really bad idea to set -minrate, -maxrate and -b:v to the same values. This will force CBR, which is the opposite of VBR, which is what people are typically looking for in 2-pass encoding. I'd recommend to simply remove -minrate/-maxrate along with -bufsize, unless you need VBV for hardware compatibility. In that case, follow the device level constraints, not bitrate target. – Ronald S. Bultje May 14 '22 at 23:13
  • Yep, overlooked that. Post fixed. – kesh May 15 '22 at 00:38