5

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
  • 223,558
  • 70
  • 607
  • 592
hermit
  • 81
  • 1
  • 1
  • 3

2 Answers2

7

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
  • 223,558
  • 70
  • 607
  • 592
evilsoup
  • 13,097
  • 3
  • 59
  • 80
  • @mark4o I'm certain it doesn't work. I've tested a low CRF and always get higher bitrates than the `-maxrate`. `-maxrate` is only used when `-bufsize` is set. In that case x264 uses VBV encoding and correctly constraints the bitrate. – slhck Mar 02 '13 at 08:58
  • The buffer size of the client is 2MB = 14000 kbits, that's why I chose that value. It seems like that the crf overrides the max bitrate constraint. Moreover is there a relationship between optimal maxbitrate and bufsize if the vbv encoding is used? – hermit Mar 04 '13 at 17:29
  • the most optimal is to use CRF mode without any additional constraints. – Display Name Nov 18 '14 at 19:08
  • `-bufsize` works perfectly , I use `-maxrate 300k` with `-bufsize 1M` I got smaller file size now. – Salem F Aug 19 '22 at 13:06
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
  • 156
  • 3