Based on CRF Guide (Constant Rate Factor in x264, x265 and libvpx), quoting:

Streaming nowadays is done a little more cleverly. YouTube or Netflix are using 2-pass or even 3-pass algorithms, where in the latter, a CRF encode for a given source determines the best bitrate at which to 2-pass encode your stream. They can make sure that enough bitrate is reserved for complex scenes while not exceeding your bandwidth.

also the article Saving on Encoding and Streaming: Deploy Capped CRF also claims that "Capped CRF" is the highest quality while also making sure bitrate does not go above X but they propose a single pass with:

ffmpeg -i input_file -crf 23 -maxrate 6750k -bufsize 6750k output_file

What's the correct way to generate the highest quality possible file inside a bitrate constraint using ffmpeg with x264?

  • 1
    I'd hazard a guess that unless you were dealing with the volume of content that YT and NF are, the small decreases in file size probably aren't going to give you a good return on the time spent doing the extra passes. But I don't know your use case.
    – stib
    Jul 23, 2019 at 12:48
  • @stib Time is not relevant, as long it stays under 24 hours for a 3 hour input. Saving on the bitrate while delivering very high video quality is the goal
    – Freedo
    Jul 23, 2019 at 21:27

2 Answers 2


What's the correct way to generate the highest quality possible file inside a bitrate constraint using ffmpeg with x264?

There is no "correct" way. This is still an evolving area of research, and about half the articles you have read on the subject are more marketing that they are science. The "correct" way may also be different for every video. Netflix for example just encodes the video a couple dozen ways, and keeps the one it thinks is best and throws the rest away.

The closest thing to a "best" single answer, would be 2 pass placebo capped CRF.

  • Ok but still, which one is better, single pass CRF capped or the other ?
    – Freedo
    Jul 23, 2019 at 21:39
  • “Best” is not caped CRF next I guess would be 2 pass caped CRF
    – SlimSCSI
    Jul 23, 2019 at 21:41
  • Best quality inside a X bitrate
    – Freedo
    Jul 23, 2019 at 21:52

I'm not sure you gathered the spirit of that article as intended. The author's point was to describe "capping" or constraining the CRF setting by creating a bandwidth ceiling per frame. The purpose of which is to constrain/limit the overall file size to a pre-defined maximum. This forcibly limits the freedom of the CRF algorithm with respect to its upper limit of bits-per-frame.

Now, take that concept and think about applying ffmpeg's 2-pass model to it. Running 2-pass on capped CRF (aka Constrained CRF) is redundant and a waste of time. First, how would you constitute the 2nd pass? If you repeat the first pass logic, you'll likely attain a smaller target file, but you'll also likely dilute the overall image quality to some extent. The target file size will still have the same maximum possible size it had before. The 2nd pass will almost undoubtedly take longer to process than the first pass, because of how the 2-pass process works in ffmpeg, and the fact you'll be compressing already compressed images again.

Overall, it's just plain a bad idea. It's a time waster and you'd likely end up with worse quality versus the first pass result. Best case scenario, they will look the same. If file size is your top priority, you need to move away from H.264 and choose a more recent codec library optimized for compression (such as h.265/HEVC or VP9, possibly AV1). Constrained CRF is not a poor idea at all, but attempting to run 2-pass encoding with it is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.