Discussion:
[x264-devel] Making sense out of x264 rate control methods
Horacio Sanson
2010-02-18 02:20:16 UTC
Permalink
I am learning how to use the rate control methods that x264 supports and
I would like to confirm that my knowledge on the topic is correct:

CQP Mode
- Always use constant QP for I, P and B frames.
- To enable in x264 use qp, ipratio and pbratio to select the
desired qp values for P, I and B frames respectively.
- Use only for first pass, a second pass offers no benefits.
- Old rate control method deprecated in favor of CRF mode.
- Not good for generating one pass log files.

x264 --qp 23 --ipratio 1.4 --pbratio 1.3 -o <output> <input>

ABR Mode
- Tries to keep the encoded media around the desired bitrate. No
guarantees.
- To enable in x264 simply set bitrate parameter.
- qp_min, qp_max and qp_step can be used to control the
quality of ABR mode?
- qp, ipratio and pbratio are ignored in ABR mode?
- Good for generating the first pass log file that can be used for
subsequent VBR or CBR second passes.

x264 --bitrate 1500 -o <output> <input>

VBR Mode
- By running ABR mode two or more passes we automatically get VBR
mode.
- Does a better job at keeping the media around the desired bitrate
than ABR but takes longer encoding time
- Good for generating second and subsequent log pass files. Run as
many times as desired but after 3 passes quality improvements are
negligible.

x264 --pass 1 --bitrate 1500 -o <output> <input> # ABR Mode
x264 --pass 2 --bitrate 1500 -o <output> <input> # VBR Mode

CBR Mode
- By running ABR mode and setting vbv_maxrate equal to bitrate we get
CBR mode.
- The hard limit in maxrate can cause high degradation in quality.
Only use if you really need to limit the bitrate below a certain
value.
- Not useful to generate first pass log files.

x264 --vbv-bufsize 2000 --bitrate 1000 -o <output> <input>

CRF Mode
- Good to keep constant quality over all the frames.
- No way to control the bitrate of the resulting file. We can vary
the CRF value until we get a desired bitrate but is better to
simply use ABR or VBR mode for this.
- 18 is the recomended setting for quality. more than 23 starts
showing quality degradation.
- One pass gives good results but can also be used for sencond and
subsequent passes.

x264 --crf 24 -o <output> <input>

Lossless Mode
- Setting CRF to 0 or QP to 0 results in lossless encoding.

x264 --crf 0 -o <output> <input>

or

x264 --qp 0 -o <output> <input>



For single pass encodings I should use use CQP, ABR, CBR, CRF or Lossless.

- Lossless if you want a perfect copy of the original and bitrate/size
is not a problem.
- ABR if you care about bitrate (e.g. streaming)
- CRF if you care about quality and bitrate/size is irrelevant.
- CQP and CBR are deprecated by CRF and CBR respectively.

For two or more pass encodings we can use ABR or CRF as first pass, VBR,
CRF as subsequent passes and VBR or CBR for last pass.

- What advantages of using each combination is beyond me. If someone
has experience with this please share.

Comments, error, tips are all appreciated....
--
regards,
Horacio Sanson
Jason Garrett-Glaser
2010-02-18 03:53:06 UTC
Permalink
?ABR Mode
? - Tries to keep the encoded media around the desired bitrate. No
? ? guarantees.
? - To enable in x264 simply set bitrate parameter.
? - qp_min, qp_max and qp_step can be used to control the
? ? quality of ABR mode?
? - qp, ipratio and pbratio are ignored in ABR mode?
? - Good for generating the first pass log file that can be used for
? ? subsequent VBR or CBR second passes.
? ? x264 --bitrate 1500 -o <output> <input>
ipratio applies to all modes. pbratio applies to all modes whenever
MB-tree is disabled.
?VBR Mode
? - By running ABR mode two or more passes we automatically get VBR
? ? mode.
? - Does a better job at keeping the media around the desired bitrate
? ? than ABR but takes longer encoding time
? - Good for generating second and subsequent log pass files. Run as
? ? many times as desired but after 3 passes quality improvements are
? ? negligible.
? ? x264 --pass 1 --bitrate 1500 -o <output> <input> ?# ABR Mode
? ? x264 --pass 2 --bitrate 1500 -o <output> <input> ?# VBR Mode
This is called 2-pass mode, not VBR mode. ABR is a form of VBR. CRF
is also a form of VBR. In fact, anything not CBR is a form of VBR.

After 2 passes the quality change is negligable, not 3.

It doesn't necessarily take a longer time, since you can use faster
settings to compensate (and may still get better results than 1-pass
ABR). In general, never use ABR mode, ever.
?CBR Mode
? - By running ABR mode and setting vbv_maxrate equal to bitrate we get
? ? CBR mode.
? - The hard limit in maxrate can cause high degradation in quality.
? ? Only use if you really need to limit the bitrate below a certain
? ? value.
? - Not useful to generate first pass log files.
? ? x264 --vbv-bufsize 2000 --bitrate 1000 -o <output> <input>
CBR is perfectly useful to generate first pass log files for a 2-pass
CBR encode. 2-pass generally doesn't help much with CBR though and
can sometimes hurt.
For single pass encodings I should use use CQP, ABR, CBR, CRF or Lossless.
No, you shouldn't use ABR ever.
?- ABR if you care about bitrate (e.g. streaming)
ABR is useless for streaming. For streaming, the best option is
capped CRF (CRF + VBV) or CBR.
?- CRF if you care about quality and bitrate/size is irrelevant.
No, CRF if you care about quality and you don't need a _specific
average bitrate_. You can still cap the local bitrate using VBV.

Dark Shikari
Horacio Sanson
2010-02-19 08:59:11 UTC
Permalink
Post by Jason Garrett-Glaser
?ABR Mode
? - Tries to keep the encoded media around the desired bitrate. No
? ? guarantees.
? - To enable in x264 simply set bitrate parameter.
? - qp_min, qp_max and qp_step can be used to control the
? ? quality of ABR mode?
? - qp, ipratio and pbratio are ignored in ABR mode?
? - Good for generating the first pass log file that can be used for
? ? subsequent VBR or CBR second passes.
? ? x264 --bitrate 1500 -o <output> <input>
ipratio applies to all modes. pbratio applies to all modes whenever
MB-tree is disabled.
?VBR Mode
? - By running ABR mode two or more passes we automatically get VBR
? ? mode.
? - Does a better job at keeping the media around the desired bitrate
? ? than ABR but takes longer encoding time
? - Good for generating second and subsequent log pass files. Run as
? ? many times as desired but after 3 passes quality improvements are
? ? negligible.
? ? x264 --pass 1 --bitrate 1500 -o <output> <input> ?# ABR Mode
? ? x264 --pass 2 --bitrate 1500 -o <output> <input> ?# VBR Mode
This is called 2-pass mode, not VBR mode. ABR is a form of VBR. CRF
is also a form of VBR. In fact, anything not CBR is a form of VBR.
Thanks, this clears out a lot of things. Anyone comparing ABR with VBR
or CRF with VBR has no idea what he is talking about.
Post by Jason Garrett-Glaser
After 2 passes the quality change is negligable, not 3.
It doesn't necessarily take a longer time, since you can use faster
settings to compensate (and may still get better results than 1-pass
ABR). In general, never use ABR mode, ever.
I always use the turbo option of mencoder when encoding in x264. It
really speeds up the first pass.
Post by Jason Garrett-Glaser
?CBR Mode
? - By running ABR mode and setting vbv_maxrate equal to bitrate we get
? ? CBR mode.
? - The hard limit in maxrate can cause high degradation in quality.
? ? Only use if you really need to limit the bitrate below a certain
? ? value.
? - Not useful to generate first pass log files.
? ? x264 --vbv-bufsize 2000 --bitrate 1000 -o <output> <input>
CBR is perfectly useful to generate first pass log files for a 2-pass
CBR encode. 2-pass generally doesn't help much with CBR though and
can sometimes hurt.
For single pass encodings I should use use CQP, ABR, CBR, CRF or Lossless.
No, you shouldn't use ABR ever.
Understood.
Post by Jason Garrett-Glaser
?- ABR if you care about bitrate (e.g. streaming)
ABR is useless for streaming. For streaming, the best option is
capped CRF (CRF + VBV) or CBR.
?- CRF if you care about quality and bitrate/size is irrelevant.
No, CRF if you care about quality and you don't need a _specific
average bitrate_. You can still cap the local bitrate using VBV.
Just to wrap this up:

If I am in a hurry and need to encode files for streaming I can use:

CBR one pass mode
- Lowest quality (at least in my tests gives lowest SSIM 0.9815)
- Resulting bitrate was lower than the desired (975.80kbps)

e.g. x264 --vbv-bufsize 2000 --vbv-maxrate 1000 --bitrate 1000 -o <output> <input>

CRF + VBV
- Second in quality (second largest SSIM 0.9818 in my tests)
- Resulting bitrate was even lower (960.16kbps). Maybe a lower CRF
would have given better SSIM and higher bitrate?? but...
- I have no idea how to select CRF value. Some forums say 18 is
the best bet.

e.g. x264 --vbv-bufsize 2000 --vbv-maxrate 1000 --crf 18 -o <output> <input>

If I have time to spend and need to encode files for streaming then:

2 Pass Encode:
- Gives the highest SSIM 0.9822 in my tests
- Resulting bitrate is very close to the desired (1001.99 kbps)
- The slower one because of two pases.

? ? e.g. x264 --pass 1 --bitrate 1000 -o <output> <input>?
x264 --pass 2 --vbv-bufsize 2000 --vbv-maxrate 1000 --bitrate 1000 -o <output> <input>

CRF with second pass CRF + VBV
- Just for testing but gave results similar so single pass CBR and
as slow as 2pass so better stick with 2pass encode.

e.g. x264 --pass 1 --crf 18 -o <output> <input>
x264 --pass 2 --vbv-bufsize 2000 --vbv-maxrate 1000 --crf 18 -o <output> <input>

If I only care about quality and bitrate/storage/time are no problem then
CRF is the way to go:.

- With CRF 18.0 gives very high SSIM 0.9900 but bitrate is
2019.07kbps.
- With CRF 23.0 gives SSIM 0.9835 and bitrate 960.46kbps


Open questions:

- How the other hundred options of x264 can affect these results?

- How to select the CRF value to use for streaming or for storage?
Post by Jason Garrett-Glaser
Dark Shikari
_______________________________________________
x264-devel mailing list
x264-devel at videolan.org
http://mailman.videolan.org/listinfo/x264-devel
--
regards,
Horacio Sanson
Jason Garrett-Glaser
2010-02-22 09:00:41 UTC
Permalink
? ?CBR one pass mode
? ? ?- Lowest quality (at least in my tests gives lowest SSIM 0.9815)
? ? ?- Resulting bitrate was lower than the desired (975.80kbps)
? ? ?e.g. x264 --vbv-bufsize 2000 --vbv-maxrate 1000 --bitrate 1000 -o <output> <input>
x264 does not currently add filler to pad to the full bitrate you
prefer. In a zero motion scene, it will not throw away bits on
nothing. When NAL HRD support is added (a week or two), --nal-hrd cbr
will make the stream exactly 1000kbps, to the last bit, through
padding.
? ?CRF + VBV
? ? ?- Second in quality (second largest SSIM 0.9818 in my tests)
? ? ?- Resulting bitrate was even lower (960.16kbps). Maybe a lower CRF
? ? ? ?would have given better SSIM and higher bitrate?? but...
? ? ?- I have no idea how to select CRF value. Some forums say 18 is
? ? ? ?the best bet.
? ? ?e.g. x264 --vbv-bufsize 2000 --vbv-maxrate 1000 --crf 18 -o <output> <input>
CRF is the quality level. 18 is roughly visually transparent--which
is not what you want here. The purpose of CRF + VBV is to stream with
a maximum bitrate, but to not waste bits where they aren't necessary.
At lower bitrates, you probably will not be perfectly transparent at
any point, so your target quality should be lower than that (higher
CRF).
? ? - Gives the highest SSIM 0.9822 in my tests
? ? - Resulting bitrate is very close to the desired (1001.99 kbps)
? ? - The slower one because of two pases.
?? ? e.g. x264 --pass 1 --bitrate 1000 -o <output> <input>
? ? ? ? ?x264 --pass 2 --vbv-bufsize 2000 --vbv-maxrate 1000 --bitrate 1000 -o <output> <input>
The first pass should probably use CBR too. Also note that 2-pass CBR
is not always better than one-pass CBR; they're generally close enough
that it it doesn't matter too much.

2-pass is better at using up all the bits though.
? ?CRF with second pass CRF + VBV
? ? ?- Just for testing but gave results similar so single pass CBR and
? ? ? ?as slow as 2pass so better stick with 2pass encode.
? ? ?e.g. x264 --pass 1 --crf 18 -o <output> <input>
? ? ? ? ? x264 --pass 2 --vbv-bufsize 2000 --vbv-maxrate 1000 --crf 18 -o <output> <input>
--crf and --pass 2 will cause an error. That commandline could not have worked.
?- How the other hundred options of x264 can affect these results?
A lot. Check the presets.
?- How to select the CRF value to use for streaming or for storage?
Start with a low CRF value (say, 18). Raise it one by one, encoding
your sample clip each time. Stop when the quality has dropped too
much to be tolerable to you, and then lower it back to the last good
CRF. Use this CRF for every video.

Dark Shikari
Horacio Sanson
2010-02-23 07:05:22 UTC
Permalink
Post by Jason Garrett-Glaser
?ABR Mode
? - Tries to keep the encoded media around the desired bitrate. No
? ? guarantees.
? - To enable in x264 simply set bitrate parameter.
? - qp_min, qp_max and qp_step can be used to control the
? ? quality of ABR mode?
? - qp, ipratio and pbratio are ignored in ABR mode?
? - Good for generating the first pass log file that can be used for
? ? subsequent VBR or CBR second passes.
? ? x264 --bitrate 1500 -o <output> <input>
ipratio applies to all modes. pbratio applies to all modes whenever
MB-tree is disabled.
?VBR Mode
? - By running ABR mode two or more passes we automatically get VBR
? ? mode.
? - Does a better job at keeping the media around the desired bitrate
? ? than ABR but takes longer encoding time
? - Good for generating second and subsequent log pass files. Run as
? ? many times as desired but after 3 passes quality improvements are
? ? negligible.
? ? x264 --pass 1 --bitrate 1500 -o <output> <input> ?# ABR Mode
? ? x264 --pass 2 --bitrate 1500 -o <output> <input> ?# VBR Mode
This is called 2-pass mode, not VBR mode. ABR is a form of VBR. CRF
is also a form of VBR. In fact, anything not CBR is a form of VBR.
Thanks, this clears out a lot of things. Anyone comparing ABR with VBR
or CRF with VBR has no idea what he is talking about.
Post by Jason Garrett-Glaser
After 2 passes the quality change is negligable, not 3.
It doesn't necessarily take a longer time, since you can use faster
settings to compensate (and may still get better results than 1-pass
ABR). In general, never use ABR mode, ever.
I always use the turbo option of mencoder when encoding in x264. It
really speeds up the first pass.
Post by Jason Garrett-Glaser
?CBR Mode
? - By running ABR mode and setting vbv_maxrate equal to bitrate we get
? ? CBR mode.
? - The hard limit in maxrate can cause high degradation in quality.
? ? Only use if you really need to limit the bitrate below a certain
? ? value.
? - Not useful to generate first pass log files.
? ? x264 --vbv-bufsize 2000 --bitrate 1000 -o <output> <input>
CBR is perfectly useful to generate first pass log files for a 2-pass
CBR encode. 2-pass generally doesn't help much with CBR though and
can sometimes hurt.
For single pass encodings I should use use CQP, ABR, CBR, CRF or Lossless.
No, you shouldn't use ABR ever.
Understood.
Post by Jason Garrett-Glaser
?- ABR if you care about bitrate (e.g. streaming)
ABR is useless for streaming. For streaming, the best option is
capped CRF (CRF + VBV) or CBR.
?- CRF if you care about quality and bitrate/size is irrelevant.
No, CRF if you care about quality and you don't need a _specific
average bitrate_. You can still cap the local bitrate using VBV.
Just to wrap this up:

If I am in a hurry and need to encode files for streaming I can use:

CBR one pass mode
- Lowest quality (at least in my tests gives lowest SSIM 0.9815)
- Resulting bitrate was lower than the desired (975.80kbps)

e.g. x264 --vbv-bufsize 2000 --vbv-maxrate 1000 --bitrate 1000 -o <output> <input>

CRF + VBV
- Second in quality (second largest SSIM 0.9818 in my tests)
- Resulting bitrate was even lower (960.16kbps). Maybe a lower CRF
would have given better SSIM and higher bitrate?? but...
- I have no idea how to select CRF value. Some forums say 18 is
the best bet.

e.g. x264 --vbv-bufsize 2000 --vbv-maxrate 1000 --crf 18 -o <output> <input>

If I have time to spend and need to encode files for streaming then:

2 Pass Encode:
- Gives the highest SSIM 0.9822 in my tests
- Resulting bitrate is very close to the desired (1001.99 kbps)
- The slower one because of two pases.

? ? e.g. x264 --pass 1 --bitrate 1000 -o <output> <input>?
x264 --pass 2 --vbv-bufsize 2000 --vbv-maxrate 1000 --bitrate 1000 -o <output> <input>

CRF with second pass CRF + VBV
- Just for testing but gave results similar so single pass CBR and
as slow as 2pass so better stick with 2pass encode.

e.g. x264 --pass 1 --crf 18 -o <output> <input>
x264 --pass 2 --vbv-bufsize 2000 --vbv-maxrate 1000 --crf 18 -o <output> <input>

If I only care about quality and bitrate/storage/time are no problem then
CRF is the way to go:.

- With CRF 18.0 gives very high SSIM 0.9900 but bitrate is
2019.07kbps.
- With CRF 23.0 gives SSIM 0.9835 and bitrate 960.46kbps


Open questions:

- How to select the CRF value to use for streaming or for storage?
Post by Jason Garrett-Glaser
Dark Shikari
_______________________________________________
x264-devel mailing list
x264-devel at videolan.org
http://mailman.videolan.org/listinfo/x264-devel
--
regards,
Horacio Sanson
Loading...