Log in

View Full Version : Lower CRF value in x264 to compensate for --tune grain?


mjr4077au
29th November 2015, 23:54
Hi Guys,

So apparently I have not logged in since 9th Dec 2007! Unbelievable!

I've recently been ripping some home videos from VHS to the PC and am high bit-rate encoding to x264. Input is 720x576 at 50fps. My video is not the best as part of it was recorded in LP with most in SP, some of the content is shot at night and has high amounts of grain, other parts are less grainy.

I was targeting a CRF of 14 without any tuning and getting around 8000Kbps, however with grain tuning, this increased to over 30000Kbps (yes, 30Mbps). File size is irreverent but quality is. By leaving the default CRF at 23 with grain tuning, the bit-rate is around 8500Kbps and the quality looks good.

My question is, should I be accepting the same CRF and increased bit-rate, or can the CRF typically be lower if you're tuning for grain?

FYI, full cmdline: x264 --preset placebo --tune grain --crf 14/23 --open-gop --output-csp yuv422p --sar 16:15 -O C:\vhsrips\dadroadtrains.264 C:\vhsrips\dadroadtrains_qtgmc50fps.avs

Outputting to yuv422p as it's the planar equivalent of my yuyv422 input.


Cheers,
Mitch.

LoRd_MuldeR
30th November 2015, 00:13
Keep in mind that CRF is not a "constant quality" mode.

The same CRF value gives approximately the same quality for different sources - but only as long as you do not change other influential settings! Using a different "--tune" option can change quite a lot! So, using "--tune grain" instead of "--tune film" or instead of default, means that the CRF values have a different meaning now - and thus you cannot compare them. As you have noticed, the bitrate went up quite a lot by using "--tune film", compared to default, at the same CRF value. But what do you learn from this? If encode A looks better than B, but also uses more bits than B, you didn't learn much. You could have gotten better quality by not using "--tune film" and just cranking up the bitrate (using lower CRF). So, what really matters is: At a given (average) bitrate X, does "--tune grain" really look better than "--tune film" or default? As long as you are comparing encodes of different (average) bitrates, you are comparing apples to bananas - and thus you don't learn anything!

Consequently, if you want to visually compare different settings, like different "--tune" options, you always have to do this at the same (average) bitrate, i.e. by using "2 Pass" mode with the same target bitrate. Only this way, you can ensure that the result isn't biased. Finally, note that "--tune grain" is intended for very high bitrate encodes, where grain can actually be retained and where the grain sucks up most of the bits. That's why it reduces AQ quite a lot. Normally, you don't want that.

mjr4077au
30th November 2015, 00:37
Keep in mind that CRF is not a "constant quality" mode.

The same CRF value gives approximately the same quality for different sources - but only as long as you do not change other influential settings! Using a different "--tune" option can change quite a lot! So, using "--tune grain" instead of "--tune film" or instead of default, means that the CRF values have a different meaning now - and thus you cannot compare them. As you have noticed, the bitrate went up quite a lot by using "--tune film", compared to default, at the same CRF value. But what do you learn from this? If encode A looks better than B, but also uses more bits than B, you didn't learn much. You could have gotten better quality by not using "--tune film" and just cranking up the bitrate (using lower CRF). So, what really matters is: At a given (average) bitrate X, does "--tune grain" really look better than "--tune film" or default? As long as you are comparing encodes of different (average) bitrates, you are comparing apples to bananas - and thus you don't learn anything!

Consequently, if you want to visually compare different settings, like different "--tune" options, you always have to do this at the same (average) bitrate, i.e. by using "2 Pass" mode with the same target bitrate. Only this way, you can ensure that the result isn't biased. Finally, note that "--tune grain" is intended for very high bitrate encodes, where grain can actually be retained and where the grain sucks up most of the bits. That's why it reduces AQ quite a lot. Normally, you don't want that.

Thank you for your quick response. You make excellent points, especially since my question was asking about subjective quality.

Regarding CRF, I know it's not constant quality, but wouldn't it be considered "consistent quality" since it's raising and lowering the bit-rate where necessary, vs using -qp 10 or something similar which would provide a computationally accurate constant quality throughout the video, but potentially worse visually?

If you were encoding a video with high amounts of grain at 720x576, roughly from experience where have you found the bit-rate should be at with x264 to achieve quality?

LoRd_MuldeR
30th November 2015, 00:47
Regarding CRF, I know it's not constant quality, but wouldn't it be considered "consistent quality" since it's raising and lowering the bit-rate where necessary, vs using -qp 10 or something similar which would provide a computationally accurate constant quality throughout the video, but potentially worse visually?

Again: What you can expect from CRF mode is that the same CRF value gives approximately the same quality for different sources.

But what you really should not expect from CRF mode is that that a certain CRF value X still gives the same quality after you changed other influential settings (such as "--tune"). That's certainly not guaranteed. And generally won't be the case!

So, while CRF is a very useful mode, you definitely should be using 2-Pass mode for comparing different settings. Once you have decided the settings that give the "best" result for your personal needs, you can go back to CRF mode.

(Of course, when you're doing your tests with 2-Pass mode, the target average bitrate should be somewhere around the average bitrates that you are expecting for your final CRF encodes. Otherwise, the results of your test could be misleading)

If you were encoding a video with high amounts of grain at 720x576, roughly from experience where have you found the bit-rate should be at with x264 to achieve quality?

Personally, I would go with something like "--crf 20" and "--tune film" for the final encode. But you probably should do your own tests :)

mjr4077au
30th November 2015, 01:01
Again: What you can expect from CRF mode is that the same CRF value gives approximately the same quality for different sources.

But what you really should not expect from CRF mode is that that a certain CRF value X still gives the same quality after you changed other influential settings (such as "--tune"). That's certainly not guaranteed. And generally won't be the case!

So, while CRF is a very useful mode, you definitely should be using 2-Pass mode for comparing different settings. Once you have decided the settings that give the "bes"t result for your personal needs, you can go back to CRF mode.

(Of course, when are doing your tests with 2-Pass mode, the target average bitrate should be somewhere around the average bitrates that you are expecting from your final CRF encodes. Otherwise, the results of your test could be misleading)

If this vBulletin forum had a Thanks button like some others I've been on, I'd certainly press it :). I really appreciate all your help.

Personally, I would go with something like "--crf 20" and "--tune film" for the final encode. But you probably should do your own tests :)

I'll test this out tonight when I get home (11am on Monday morning in Sydney). Using --tune grain might be too much for what I'm doing, it certainly changes many more parameters than --tune film.

Thanks again :)

jpsdr
2nd December 2015, 10:22
Personally, I would go with something like "--crf 20" and "--tune film" for the final encode. But you probably should do your own tests :)
You don't talk about the preset, unless you consider using the default preset.
Same rule of course apply to preset, changing it can greatly affect the result for a same crf value.

smok3
2nd December 2015, 11:30
In some cases it could be useful to use the constraint/capped CRF mode, like
ffmpeg -i in -pix_fmt yuv420p -vcodec libx264 -preset veryslow -crf 21 -threads 0 \
-maxrate 10000k -bufsize 20000k out.mp4
I guess the case would be where you have a lot of files and for most you are aware that they will stay under 10000k. The quality will suffer overall thought.
Not sure what would happen (did not test) if one wouldn't cap the bufsize (qualitywise).