Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

MKV playback, recompression, remuxing, codec packs, players, howtos, etc.
hogfan
Posts: 13
Joined: Sat Oct 29, 2016 3:33 am

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by hogfan »

Morku wrote:
Sun Jan 09, 2022 8:26 pm
Great tutorial. Thank you.

Can you specify a little more the use of the crop -c?
E.g. I crop a movie to 3840x1608. I think I have to crop the EL to 1920x804. How do I use this command? I can't find an example.

Thanks in advance.
In regards to cropping, read over this thread and it should make sense. The replies in this thread are by the dovi_tool developer quietvoid.

viewtopic.php?style=6&t=25163#p108250

Essentially, whenever you extract the RPU, if you cropped the black letterbox bars out of your x265 encoded video (in Fastflix in my example use case), then you should use -c switch when extracting the RPU.

If you did not crop the black letterbox bars, (or there were none to crop), simply don't use the -c switch in your dovi tool command when extracting the RPU.

So for an example:

Looking back at the full command to pipe and extract the RPU:

ffmpeg -i "D:\Rips\The Matrix (1999)\The Matrix_dv7.mkv" -c:v copy -vbsf hevc_mp4toannexb -f hevc - | dovi_tool -m 2 -c extract-rpu - -o "D:\Rips\The Matrix (1999)\RPU_81.bin"

a.) If you didn't crop the black bars in your x265 encode: dovi_tool -m 2
b.) If you DID crop the black bars in your x265 encode: dovi_tool -m 2 -c
hogfan
Posts: 13
Joined: Sat Oct 29, 2016 3:33 am

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by hogfan »

profzelonka wrote:
Mon Jan 10, 2022 6:58 am
This is super helpful thank you for writing this all down and sharing. Is there any idea of what the EL.hevc even is? I put an EL into an MKV container and it looks like a highlight detail layer of some sort. I have seen profile 8 mkvs with FEL included that work (but only with AC3 audio, not with TrueHD!). I'll try it out and see what works and what doesn't I guess.. (Testing on a Sony Bravia only.)
The EL is exactly what it is called, an "enhancement layer". UHD Blu Ray titles will either have:

MEL: Minimum Enhancement Layer (BL + MEL + RPU)
FEL: Full Enhancement Layer (BL + FEL + RPU)

Both of the above are Dolby Vision Profile 7, Dual Layer, Dual Track.

What MakeMKV does is take this DV Profile 7 that is two tracks (BL track + EL track) and interleaves them into a single track. So you end up with a Dolby Vision Profile 7 MKV file that is a Single Track (BL w/ interleaved EL + RPU)

For MEL titles, the EL doesn't really do anything other than house the RPU data. When we convert our DV Profile 7 MKV to DV Profile 8.1 we are doing two things:

- DV Profile 8.1 is Single-Layer Dolby Vision
- DV Profile 8.1 has backwards compatibility for HDR10 (falls back to HDR10 on devices that can't play DV)

Since DV Profile 8.1 is a single layer profile, the EL gets discarded......BUT since in the case of MEL the EL only houses the RPU data (which we extract and inject back into our x265 encoded video) we don't really lose anything.

So in short: DV Profile 8.1 = (BL w/RPU data interleaved). It's the same quality as DV Profile 7 MEL, just in a Single-Layer profile.

Now for FEL, what is happening is we are converting FEL to MEL, and then to Profile 8.1

MEL & FEL ONLY exist in DV Profile 7, which is Dual Layer DV (BL + EL).

Unlike MEL (minimum enhancement layer), the FEL (Full Enhancement Layer) track in the DV Profile 7 houses much more than just the RPU data. It's an actual EL than provides additional detail enhancements to the movie. However, to utilize the FEL, your player must be able to play back two separate hevc tracks simultaneously (the main movie at 4K resolution - BL, AND the detail enhancements at 1080 resolution - FEL). No mainstream streaming devices can to this currently, only Blu Ray players.

So to fully summarize, my process will let you keep DV for MEL and FEL titles, but only at MEL quality. Sorry for the long read, but hope this helps other understand better.
Morku
Posts: 3
Joined: Fri Jan 07, 2022 5:16 pm

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by Morku »

@hogfan

Thank you for clarify that no(?) value behinde -c is necessary, but this confuse me even more. Maybe I have a wrong idea about the EL overall.

I crop the movie (BL) to 3840x1608 and when I inject DV into my encoding, it will crop automatic 138:138 from top and bottom of the EL, because of my crops in the main movie?
How the tool knows how much I croped from top and bottom? I have seen Blu-ray movies with different size letterboxes (very rare). Does it just crop automatically 50:50 from top and bottom?
It's even more confusing that the -c value is at extract rpu instead of injecting, because I extract from the uncropped original file.

I am asking, because at the end I can't test the result for now since I don't have DV compatible Hardware :\ So I would like to avoid any user error.

Anyway, you say, if FEL it should be convert to MEL before. How do I know if I have FEL or MEL?
This is the info BDInfo gives me:

Code: Select all

MPEG-H HEVC Video       0 kbps              2160p / 23.976 fps / 16:9 / Main 10 @ Level 5.1 @ High / 10 bits / HDR10 / BT.2020
* MPEG-H HEVC Video     0 kbps              1080p / 23.976 fps / 16:9 / Main 10 @ Level 5.1 @ High / 10 bits / Dolby Vision / BT.2020
and after MakeMKV muxing, I have:

Code: Select all

HDR format                  : Dolby Vision, Version 1.0, dvhe.07.06, BL+EL+RPU, Blu-ray compatible / SMPTE ST 2086, HDR10 compatible
I have tried this tutorial for StaxRip with the extracted profile 8.1 (command: dovi_tool -m 2 -c extract-rpu - -o "D:\RPU_81.bin")

But I don't have luck overall :( When I start the encoding, StaxRip directly quits encoding with the error:

Code: Select all

x265 [FLAW]: Dolby Vision requires VBV settings to enable HRD.
x265 [FLAW]: x265_encoder_open() failed for Enc, 
x265 [WARN]: Dolby Vision RPU count is greater than frame count in x265
x265 [INFO]: VES muxing with Dolby Vision RPU file successful in x265
I could try encoding first and injecting after (as you suggest), but I think the frame count error will abort as well.
ArArdin
Posts: 187
Joined: Fri Nov 20, 2020 1:40 pm

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by ArArdin »

Morku wrote:
Sun Jan 09, 2022 8:26 pm
E.g. I crop a movie to 3840x1608. I think I have to crop the EL to 1920x804.
I wonder if muxing FEL (self recoded/cropped or not) back together with a recoded baselayer is ever gonna work. I've tried this (keeping profile 7), but image is screwed up and stutters. Frametype matching going lost during recode could be a cause. I do wonder what device is able to process these kind of files fully and properly.
profzelonka wrote:
Mon Jan 10, 2022 6:58 am
I have seen profile 8 mkvs with FEL included that work (but only with AC3 audio, not with TrueHD!).
I did not know this was possible, profile 8 being HDR10 BL+RPU. Could you post mediainfo of such a file?
Morku wrote:
Tue Jan 11, 2022 8:16 pm
How do I know if I have FEL or MEL?
When you import your movie in MakeMKV and you select the videostream, it will tell you "BL+MEL+RPU" or "BL+FEL+RPU".
hogfan
Posts: 13
Joined: Sat Oct 29, 2016 3:33 am

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by hogfan »

Morku wrote:
Tue Jan 11, 2022 8:16 pm
@hogfan

Thank you for clarify that no(?) value behinde -c is necessary, but this confuse me even more. Maybe I have a wrong idea about the EL overall.

I crop the movie (BL) to 3840x1608 and when I inject DV into my encoding, it will crop automatic 138:138 from top and bottom of the EL, because of my crops in the main movie?
How the tool knows how much I croped from top and bottom? I have seen Blu-ray movies with different size letterboxes (very rare). Does it just crop automatically 50:50 from top and bottom?
It's even more confusing that the -c value is at extract rpu instead of injecting, because I extract from the uncropped original file.

I am asking, because at the end I can't test the result for now since I don't have DV compatible Hardware :\ So I would like to avoid any user error.

Anyway, you say, if FEL it should be convert to MEL before. How do I know if I have FEL or MEL?
This is the info BDInfo gives me:

Code: Select all

MPEG-H HEVC Video       0 kbps              2160p / 23.976 fps / 16:9 / Main 10 @ Level 5.1 @ High / 10 bits / HDR10 / BT.2020
* MPEG-H HEVC Video     0 kbps              1080p / 23.976 fps / 16:9 / Main 10 @ Level 5.1 @ High / 10 bits / Dolby Vision / BT.2020
and after MakeMKV muxing, I have:

Code: Select all

HDR format                  : Dolby Vision, Version 1.0, dvhe.07.06, BL+EL+RPU, Blu-ray compatible / SMPTE ST 2086, HDR10 compatible
I have tried this tutorial for StaxRip with the extracted profile 8.1 (command: dovi_tool -m 2 -c extract-rpu - -o "D:\RPU_81.bin")

But I don't have luck overall :( When I start the encoding, StaxRip directly quits encoding with the error:

Code: Select all

x265 [FLAW]: Dolby Vision requires VBV settings to enable HRD.
x265 [FLAW]: x265_encoder_open() failed for Enc, 
x265 [WARN]: Dolby Vision RPU count is greater than frame count in x265
x265 [INFO]: VES muxing with Dolby Vision RPU file successful in x265
I could try encoding first and injecting after (as you suggest), but I think the frame count error will abort as well.
To confirm in regards to your cropping question, I asked quietvoid (developer of dovi_tool) directly in the last comment on this github issue as I wanted to understand how it determines how to set the correct active area in the RPU data.

https://github.com/quietvoid/dovi_tool/issues/39

It has no knowledge of the letterbox bars size, they are simply set to zero, to tell the Dolby Vision decoder that there are no letterbox bars encoded in the video.
speeddemon
Posts: 77
Joined: Wed Oct 16, 2019 3:44 am

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by speeddemon »

I ran into a significant memory leak on Windows that caused dovi_tool to be unusable, but I moved over to macOS and have been able to extract RPUs for most movies in a couple minutes.

NVMe storage speed seems to be the limiting factor for me (don't run over a network connection or on a slow disk). This has been a quick and straightforward process once I determined a personal workflow.

It would be incredible if someone could fully automate the process and just simply ask for an original MKV and compressed MKV at the command line and output a DoVi Profile 8.1 MKV.
hogfan
Posts: 13
Joined: Sat Oct 29, 2016 3:33 am

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by hogfan »

speeddemon wrote:
Mon Jan 17, 2022 3:17 am
I ran into a significant memory leak on Windows that caused dovi_tool to be unusable, but I moved over to macOS and have been able to extract RPUs for most movies in a couple minutes.

NVMe storage speed seems to be the limiting factor for me (don't run over a network connection or on a slow disk). This has been a quick and straightforward process once I determined a personal workflow.

It would be incredible if someone could fully automate the process and just simply ask for an original MKV and compressed MKV at the command line and output a DoVi Profile 8.1 MKV.
Glad to hear the process is working well for somebody else. It's not too bad, just a lot of steps. I actually started trying to put a simple GUI together to automate the process, but haven't had a lot of time to work on it. I'm still doing all the steps manually myself.

Image
upload

One thing I have noticed after I recently used the "Help Menu" to "Download the Newest FFMPEG" from within the Fastflix application is that my x265 encoded movie in Fastflix is now retaining the Dolby Vision metadata from the source file after the encode. In the past, this metadata was always ignored/lost during the encode. (Looking at the Fastflix encoded file in Mediainfo shows it to be DV profile 7 (BL+ EL + RPU).

I extracted the hevc track from the encoded mkv and then ran:

dovi_tool demux [Path to extracted hevc track] to split it into a BL + EL hevc tracks. The EL track written from this command was 0 bytes. I just discarded this.

I then took the BL.hevc, and muxed it back into an MKV container just to confirm that the DV metadata was gone. Mediainfo now showed no Dolby Vision profile, only HDR10 Compatible.........

So finally I took that BL.hevc file and injected my DV 8.1 RPU into it, then used it to build my final MKV which shows DV 8 in Mediainfo. (DV Profile 8.1 MKV as expected)

So for now, to be safe, I'm adding that dovi_tool demux step in after encoding to ensure my encoded BL video track is only HDR10 before I inject the 8.1 RPU into it.

I'm not sure if FFMPEG is now correctly retaining the original DV data during encode or what, but it seems bad to inject DV profile 8.1 RPU into a file that is already showing a DV profile. So before injecting the 8.1 RPU, I just use dovi_tool demux to remove the RPU/EL to ensure the hevc BL track is only HDR10 w/ no DV metadata.

Then I resume the process, injecting the 8.1 RPU into the clean BL.hevc and use that to build the final 8.1 MKV.
ArArdin
Posts: 187
Joined: Fri Nov 20, 2020 1:40 pm

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by ArArdin »

hogfan wrote:
Fri Jan 21, 2022 3:29 am
One thing I have noticed after I recently used the "Help Menu" to "Download the Newest FFMPEG" from within the Fastflix application is that my x265 encoded movie in Fastflix is now retaining the Dolby Vision metadata from the source file after the encode.
I wonder if RPU is really contained. Did you try to play back the x265 direct output and see if Dolby Vision is triggered? It would mean that newest ffmpeg would have such same capabilities as MakeMKV, to properly mux BL and (EL with RPU) into dual layer single track profile 7 DoVi. Which I honestly doubt.

I'd sooner think there is something not right with newest ffmpeg. As you state, EL size ends up 0 after demux. I suspect EL is still ignored but some leftovers are still there (other metadata maybe?).
A reason to "DV profile 7 (BL+EL+RPU)" that MediaInfo shows can be that ffmpeg simply wouldn't change this source information in the output. All 'n all, I think dovi_tool's demux indeed can be a wise step to get rid of garbage and false metadata.
What I always do is demuxing into BL and EL before encoding.
hogfan
Posts: 13
Joined: Sat Oct 29, 2016 3:33 am

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by hogfan »

ArArdin wrote:
Sat Jan 22, 2022 10:31 am
hogfan wrote:
Fri Jan 21, 2022 3:29 am
One thing I have noticed after I recently used the "Help Menu" to "Download the Newest FFMPEG" from within the Fastflix application is that my x265 encoded movie in Fastflix is now retaining the Dolby Vision metadata from the source file after the encode.
I wonder if RPU is really contained. Did you try to play back the x265 direct output and see if Dolby Vision is triggered? It would mean that newest ffmpeg would have such same capabilities as MakeMKV, to properly mux BL and (EL with RPU) into dual layer single track profile 7 DoVi. Which I honestly doubt.

I'd sooner think there is something not right with newest ffmpeg. As you state, EL size ends up 0 after demux. I suspect EL is still ignored but some leftovers are still there (other metadata maybe?).
A reason to "DV profile 7 (BL+EL+RPU)" that MediaInfo shows can be that ffmpeg simply wouldn't change this source information in the output. All 'n all, I think dovi_tool's demux indeed can be a wise step to get rid of garbage and false metadata.
What I always do is demuxing into BL and EL before encoding.
I agree with you and doubt that the DV7 metadata present after the encode is valid. That's why I've been demuxing to strip it out. I may change my work flow to:

1.) Extract 8.1 compatible RPU from original source MKV
2.) Demux original MKV and then use dovi_tool to demux the hevc stream into BL & EL (discard enhancement layer)
3.) Remux into a new MKV with just the extracted BL hevc + the other audio, subtitle tracks + chapters.xml)
4.) Encode the newly muxed BL-only MKV in Fastflix.
5.) Use the Fastflix encoded MKV to build the final MKV after injecting the RPU from step 1 above into the x265 encoded hevc stream.

So many steps............
ArArdin
Posts: 187
Joined: Fri Nov 20, 2020 1:40 pm

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by ArArdin »

Looks better indeed. As I don't use it, can't you just import the BL.hevc into Fastflix, recode and output as hevc again?
I ask this because - if nothing has changed in the meanwhile - quietvoid's dovitool needs an elementary stream to inject RPU into. The way I see it, it would save you the steps of muxing the first mkv and after recode, demuxing to hevc again to be able to inject RPU. Before you go do your mux for MakeMKV import, you can inject RPU into Fastflix's recoded BL.hevc. Or am I seeing it wrong?
Morku
Posts: 3
Joined: Fri Jan 07, 2022 5:16 pm

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by Morku »

After reading several posts and threads, my workflow is currently like be...

1. Rip folderstructure of UHD (Backup)
2. load "Blu-ray Folder" in Staxrip to extract Video/Auto/Subs
3. Do the Encoding stuff the way you like (Staxrip also Import VUI metadata for HDR10), but don't mux
4. Extract secondary Videostream (FEL/MEL) from mpls movie (use BDInfo if doubts) with tsMuxer
5. I run "dovi_tool.exe -m 2 -c extract-rpu -i secondarystream.hevc -o rpu.bin" (without c, if no crop)
6. and after encoding "dovi_tool inject-rpu -i encodedmovie.hevc --rpu-in rpu.bin -o injected_output.hevc"
7. load everything back into StaxRip to do the final mkvmerge

Still not sure if everything is right, since I don't have a playback device to test, but MediaInfo says: HDR format : Dolby Vision, Version 1.0, dvhe.08.06, BL+RPU, HDR10 compatible / SMPTE ST 2086, HDR10

Also the size of the FEL hevc is 10GB. The extracted RPU.bin 25MB. The difference is big and I wonder what kind of information gets lost.

I also wonder whats the difference when I use x265 with "--dolby-vision-profile 8.1 --dolby-vision-rpu rpu.bin". It refuse to encode, because I don't set VBV size. Honestly I don't know what it wants from me. I always encode with crf.

Pretty sure I am doing a lot wrong. So any improvement recommendation is welcome :)
ArArdin
Posts: 187
Joined: Fri Nov 20, 2020 1:40 pm

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by ArArdin »

Morku wrote:
Tue Jan 25, 2022 6:31 pm
It refuse to encode, because I don't set VBV size. Honestly I don't know what it wants from me. I always encode with crf.
It's asking for VBV parameters. Being safe for HW players compatibility to BD specs, you can use --uhd-bd. This will suffice in a lot of cases.
Usually, when not using --uhdbd, you set VBV params according to the used level. For example:

--level-idc=51 --high-tier=1 --vbv-maxrate=160000 --vbv-bufsize=160000
Morku wrote:
Tue Jan 25, 2022 6:31 pm
Also the size of the FEL hevc is 10GB. The extracted RPU.bin 25MB. The difference is big and I wonder what kind of information gets lost.
MEL (Minimal Enhancedment Layer) just holds RPU. FEL (Full Enhancedment Layer) also holds additional videodata. Therefor FEL is always significantly bigger than MEL.
FYI this additional color enhancement data is used - together with 10 bit BL - by the Dolby Vision compiler to create full 12 bit color video. Other than DV compatible UHD-BD players, not much mediaplayers support FEL playback. Only BL and RPU are used.
mtotheb
Posts: 30
Joined: Wed Jan 27, 2021 12:18 pm

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by mtotheb »

Has anyone tried compressing the 4k movie to 1080p and then inject the DV part? Does that work or do we have to stay at the original resolution?
Shield TV 2017 -> LG DSN10YG Soundbar with SPK8 Rears -> LG B1 OLED
ArArdin
Posts: 187
Joined: Fri Nov 20, 2020 1:40 pm

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by ArArdin »

mtotheb wrote:
Thu Jan 27, 2022 2:57 pm
Has anyone tried compressing the 4k movie to 1080p and then inject the DV part? Does that work or do we have to stay at the original resolution?
Interesting question. I never gave DV for 1080p much thought. Profile 7 RPU is hold by 1080p EL. Profile 7 also supports FHD, if wiki is correct. It does make you wonder if the RPU could indeed be used for FHD video.

Why don't you give it a go? Should it make your tv explode, please be so kind to warn us? :mrgreen:
quietvoid
Posts: 371
Joined: Sun Apr 19, 2020 4:15 pm

Re: Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by quietvoid »

Technically the RPU metadata would have to be recalculated for a compressed/downscaled reencode.
However in practice it doesn't really matter as long as the encode is close enough.

The only thing to be aware about is the L5 metadata, depending if the 1080p was cropped or not.
Post Reply