6

I am trying to transcode a video to H.264/MP4. I am using the crf = 20 option but according to the requirements I also want to limit the maximum bitrate to 3 MBit/s.

I was trying to cheat though it by using x264opts like this

-x264opts crf=20:vbv-bufsize=14000:vbv-maxrate=3000:keyint=40

is that the right way to do this? Can this be done or I am stuck with using a contant bitrate and no CRF?

slhck
  • 235,242
hermit
  • 91
  • 1
  • 1
  • 3

2 Answers2

8

Use -maxrate and -bufsize to force the VBV (Video Buffer Verifier) to constrain the output bitrate:

ffmpeg -i input.file -c:v libx264 -crf 20 -maxrate 3M -bufsize 6M output.mp4

3M = 3 mbit/s, you could also use 3000k (for 3000 kbit/s). Set the buffer size according to how much you expect your client to be able to buffer.

See this guide for more information on using x264 with FFmpeg (although it doesn't mention VBV encoding).

slhck
  • 235,242
evilsoup
  • 14,056
1

Just a fair warning for others reading this; I've noticed that VBV (ffmpeg -maxrate for x264) is far more indiscriminate about what bits it throws away, than a proper 2-pass rate-controlled encode. A much better (but also, trickier, and more expensive) approach is to encode the entire video using CRF, and then re-encode the offending peaking segments using 2-pass with bitrate-target.

OR, use a newer codec with better encoder-support for capped CRF (I.E. AV1)

Rawler
  • 166