Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

General questions or discussion about HandBrake, Video and/or audio transcoding, trends etc.
Post Reply
metaldave
Posts: 36
Joined: Mon Apr 10, 2017 6:40 pm

Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

Post by metaldave »

Hello, Community!

I've had a chance to look through the forum, but this is a dense and complex topic. I thought I'd try asking with my own log attempt. Please excuse if I'm repeating; I'd appreciate a pointer to any previous discussion on this topic.

I've read through the documentation, and everything points to moving the Constant Quality slider to a lower number to increase quality and, correspondingly, file size. For giggles, I tried an RF value of zero (0) to see if this would translate to a close to original video quality. While things start becoming indiscernible at a certain point, I thought it would be a worth experiment.

The source file was a copy of Despicable Me (2010). The original video stream is in AVC (Codec V_MPEG4/ISO/AVC) format (as opposed to VC-1). I don't know how the H.264 Encoder should behave when encountering AVC versus VC-1, but I'm curious to know if this translates to any encoding process savings if we're already in an H.264 format (AVC).

After performing the encode with the RF slider set to zero (0), the end result was the stream size doubled from the original AVC stream. What is Handbrake doing? "Enhancing" the video? I'm guessing not, but why would it do something more than, effectively, pass through the original stream? I'm guessing the H.264 encoder is always going to run, so I would accept a small bump. Double the size seems a little egregious.

Incidentally, the pop-up help balloon on the RF slider says "x264 is lossless at RF 0" (Handbrake v1.0.7), and that inspired the test.

Thanks in advance!

- Dave
mduell
Veteran User
Posts: 8187
Joined: Sat Apr 21, 2007 8:54 pm

Re: Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

Post by mduell »

The H.264 encoder doesn't give a [Censored] what the prior encoder was. The H.264 encoder in HB is being fed raw video from the decoded bitstream.

There's no enhancement, just reproduction of both content and defects.

If you want passthrough video from a disk (DVD or Blu-ray), use MakeMKV not HandBrake.
metaldave
Posts: 36
Joined: Mon Apr 10, 2017 6:40 pm

Re: Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

Post by metaldave »

  • I suspected there would be no "enhancement," but it's still curious how the encoder created a double-size video stream.
  • I also implied the encoder will always encode (as there's no video passthrough option), so there's no true apples-to-apples comparison.
  • A straight MakeMKV rip may not play well in every media player. Playback performance depends upon the source stream format and the natively supported formats of a given media player. An example of this would be a VC-1 video stream used on a player optimized for H.264 or H.265 decoding in hardware. Thus, Handbrake encoding all video streams to H.264 is desirable for consistency in the library.
My follow-up questions:
  • To be clear: Handbrake is claiming in-software that Constant Quality with an RF value of zero (0) is lossless; I'm trying to have some clarification what "lossless" infers in this case.
  • Can we conclude a "lossless" (Constant Quality, RF=0) encode with the Handbrake H.264 (x264) Encoder will consistently a larger size file than the AVC stream on the disc?
I'd like to develop a cookbook with recipes for workflow scenarios, so feedback on this topic is appreciated.
mduell
Veteran User
Posts: 8187
Joined: Sat Apr 21, 2007 8:54 pm

Re: Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

Post by mduell »

metaldave wrote: Tue Aug 15, 2017 5:27 amI suspected there would be no "enhancement," but it's still curious how the encoder created a double-size video stream.
Reproducing all the defects of the prior encode, from the raw video (as decoded from the source bitstream).
metaldave wrote: Tue Aug 15, 2017 5:27 amTo be clear: Handbrake is claiming in-software that Constant Quality with an RF value of zero (0) is lossless; I'm trying to have some clarification what "lossless" infers in this case.
There is no loss, the decoded picture is the same as the source.
metaldave wrote: Tue Aug 15, 2017 5:27 amCan we conclude a "lossless" (Constant Quality, RF=0) encode with the Handbrake H.264 (x264) Encoder will consistently a larger size file than the AVC stream on the disc?
For sure, every time.
metaldave wrote: Tue Aug 15, 2017 5:27 amI'd like to develop a cookbook with recipes for workflow scenarios, so feedback on this topic is appreciated.
Don't [Censored] around with lossless. Pick reasonable settings.
metaldave
Posts: 36
Joined: Mon Apr 10, 2017 6:40 pm

Re: Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

Post by metaldave »

Great feedback. Thanks, mduell.
User avatar
BradleyS
Moderator
Posts: 1860
Joined: Thu Aug 09, 2007 12:16 pm

Re: Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

Post by BradleyS »

Take a lossy mp3/aac audio file and re-encode it as lossless wav/flac/alac. The quality will be identical, but the file size will be larger. This is the nature of lossless encoding from a lossy source (read: don't do it).

We have an article called Adjusting Quality in the documentation that discusses sane lossy settings: https://handbrake.fr/docs/en/1.0.0/work ... ality.html

Generally speaking, with x264 it is possible to achieve perceptually equal quality while reducing file size. I suggest never using lower than crf 16 unless you have an academic reason.
metaldave
Posts: 36
Joined: Mon Apr 10, 2017 6:40 pm

Re: Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

Post by metaldave »

BradleyS wrote: Tue Aug 15, 2017 3:01 pmWe have an article called Adjusting Quality in the documentation that discusses sane lossy settings: https://handbrake.fr/docs/en/1.0.0/work ... ality.html
Thanks, Bradley. That article provides some great preliminary guidance, and I appreciate you expanding upon that a bit further.

I'm also interested in further details of the actual affect of the x264 Presets. As indicated in the Technical Documentation, there is a range from UltraFast to Placebo for the x264 encoder, but there's no break-down of the steps in between. If there is a breakdown of the all the x264 encoder presets (indicating cause and effect), please let us know.

Others have noted that "medium" is, essentially, the default x264 Preset. For sure, the encode settings seem to have the least number of arguments when "medium" is selected. The documentation also seems to indicate "medium" is used in most of the Official Handbrake Presets. Would you elaborate on why we might use the "slow" x264 Preset versus the "medium?"

Thanks again!
User avatar
BradleyS
Moderator
Posts: 1860
Joined: Thu Aug 09, 2007 12:16 pm

Re: Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

Post by BradleyS »

Generally speaking, with quality-based encoding and slower encoder presets, you should achieve better compression (smaller files). Some nearly imperceptible benefits to quality may present as well, usually not more than lowering the RF a little. That said, there are many variables involved, so in practice this isn't perfect.

Here's a somewhat dated table showing the differences between x264 presets; some mappings are not current but you get the idea: http://dev.beandog.org/x264_preset_reference.html

The x265 project publishes their own documentation on the subject: http://x265.readthedocs.io/en/default/presets.html

Your best bet is probably sticking with the HandBrake presets, if only because slower encoder presets can affect compatibility with some devices. If you click through HandBrake's General presets, from Very Fast 1080p30 through Super HQ 1080p30 Surround, you can see some choices we made pertaining to the encoder presets and RF values.
metaldave
Posts: 36
Joined: Mon Apr 10, 2017 6:40 pm

Re: Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

Post by metaldave »

Bradley,

Those references are a fantastic deep-dive into the encoder settings. Thank you very much for posting those links! You're right; some of the x264 table data is dated, but it's nice to see it laid out. Perhaps that type of table is something we could maintain in the HandBrake documentation? I'd offer to put some cycles into documentation myself (if you're looking for assistance in this area).

My main cause for the deep examination of these settings is the encoding of the current crop of CG animated films. Unlike live action film, the quality drop is noticeable (at least to my eyes), and I've been trying to get it closer to indiscernible from the source. Generally, this means a 5 GB file becomes 10 GB, but that's still better than the original 25 GB rip. Most kids (and spouses) could care less, but I'm looking for a happy medium in the workflow. 4K upscaling reveals more artifacts as well, so I'm trying to future proof my new library as best as possible without too much of a cost (with respect to storage).

I'll post my final workflow settings after a little bit of testing and tweaking today. Thanks again!

- Dave
rollin_eng
Veteran User
Posts: 4840
Joined: Wed May 04, 2011 11:06 pm

Re: Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

Post by rollin_eng »

Don't upscale as it's not worth it.

Post your logs so we can see what you are doing.
User avatar
BradleyS
Moderator
Posts: 1860
Joined: Thu Aug 09, 2007 12:16 pm

Re: Lossless Video Quality from Blu-Ray Source (H.264 Encoder)

Post by BradleyS »

The documentation these days is focused on workflows for normal humans. Official presets, mostly. I will likely add some links in the technical section at some point. That said, my todo list is quite long at the moment and this is fairly low priority.
Post Reply