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

Dolby Vision x265 Encoding, DV Profile Advantages/Caveats?

Post by hogfan »

So I believe after waiting some time, and doing a LOT of reading about Dolby Vision I have finally completed my first successful UHD BR Rip Dolby Vision encodes.

I use the FastFlix application to encode my UHD BR Rips that don't have Dolby Vision, so to date, I've simply been keeping the DV rips as MKV remuxes since encoding them loses the DV information.

After doing a lot of reading (again) on Dolby Vision I believe I have successfully compressed one of my Dolby Vision MKVs, and retained Dolby Vision (although profile-converted).

My process is as follows:

1.) Encode my original DV Profile 7 MKV (source.mkv) in FastFlix, outputting a new x265 encoded mkv. (encoded.mkv)
2.) Next I use ffmpeg to pipe the original source MKV to dovi_tool to extract the RPU from the source file, and convert the RPU to Dolby Vision Profile 8.1 compatible (if I cropped the letterbox bars when encoding in Fastflix, then I make sure to use the --crop option when extracting the RPU from source.mkv)

Code: Select all

ffmpeg -i "D:\Rips\mymovie.mkv" -c:v copy -vbsf hevc_mp4toannexb -f hevc - | dovi_tool -m 2 --crop extract-rpu - -o mymovie_RPU_81.bin
3.) Next I use MKVExtractGUI tool to extract the hevc video track, Audio track(s), & Subtitle track(s), & chapters from my encoded.mkv

4.) I then use dovi_tool to inject my extracted RPU (mymovie_RPU_81.bin) into the encoded HEVC video file

Code: Select all

dovi_tool inject-rpu -i "D:\Encodes Completed\mymovie\track1_[und].hevc" --rpu-in mymovie_RPU_81.bin -o mymovie_injected.hevc
5.) Finally, I open MKVToolnix 63.0.0 and use the Multiplexer to create a new MKV, adding the following source files:

- mymovie_injected.hevc
- Audio Track(s) extracted back in Step 3 above
- Subtitle Track(s) extracted back in Step 3 above
- Chapters XML file extracted back in Step 3 above

A check of the newly multiplexed MKV file (mymovie.dv8.mkv) created in Mediainfo shows the HDR format to be:

Dolby Vision, Version 1.0, dvhe.08.06, BL+RPU, HDR10 compatible / SMPTE ST 2086, HDR10 compatible

When I play this file with the Plex client/app on my Nvidia Shield 2019 Pro --> Yamaha Receiver --> LG OLED TV, the Dolby Vision logo pops up on the screen, and I have working PGS subtitles, and Dolby TrueHD audio.

So it sounds like I have successfully encoded my UHD movie, shrinking it down in size (x265 CRF 18), and retained Dolby Vision (although converting it to Single Layer Profile 8.1)

Is there anything I'm missing here I should be aware of in regards to the DV profile? I chose to convert to profile 8.1 rather than profile 5 to ensure HDR10 compatibility. This way if the file is played on a Samsung TV for example, it won't fail to play (as it would with DV Profile 5), it will just fall back to HDR10.

Is there any big negative to using profile 8.1 vs profile 5 for UHD Bluray source encodes? The spec sheet I read shows both profiles are (BL + RPU) with the main differences being profile 5 uses the IPT color space which is proprietary to Dolby. Does profile 8.1 use the same color space as profile 7 (BL+MEL/FEL+RPU)? From what I read, it seems to imply the IPT color space is unique to profile 5.

It seems Profile 5 & Profile 8.1 are very similar to HDR10+, dynamic metadata only (RPU, not EL). Is my reasoning here correct?

I plan to store my source MKV remuxes on an external drive so I'll always have the 1:1 copies, but encoding with x265 will free up a ton of space on my Plex server.

Answers to any of my questions above are greatly appreciated, and hopefully this thread can help others who are looking to compress DV movies with x265.
ArArdin
Posts: 187
Joined: Fri Nov 20, 2020 1:40 pm

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

Post by ArArdin »

Interesting thread. Thanks for your elaborate post on workflow.

How do you deal with FEL? Do you ignore it and only remux profile-converted RPU with your re-encode?
In case of FEL, I think RPU is meant to be applied to the full 12bit video.

Also (not my personal experience) I have read there are issues with certain players that would fill the screen with grey bars (not black) in case video is cropped. Maybe it's safer to keep the black bars during re-encode?
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:
Wed Nov 24, 2021 8:34 am
Interesting thread. Thanks for your elaborate post on workflow.

How do you deal with FEL? Do you ignore it and only remux profile-converted RPU with your re-encode?
In case of FEL, I think RPU is meant to be applied to the full 12bit video.

Also (not my personal experience) I have read there are issues with certain players that would fill the screen with grey bars (not black) in case video is cropped. Maybe it's safer to keep the black bars during re-encode?
Correct, I'm simply using dovi_tools to extract the RPU, convert the RPU to Profile 8 compatible, discard the MEL/FEL, and then inject the converted RPU data back into the re-encoded Base Layer video track. As I understand it, there aren't really any streaming players out there that are capable of playing the FEL. I'm using the 2019 Nvidia Shield, and although DV Profile 7 files play just fine in Plex and trigger Dolby Vision on my LG TV, I've read that the FEL is basically ignored and not played back (as I understand it, it's a hardware limitation with the current chipsets and implementation since DV Profile 7 Dual Layer is a UHD Blu Ray Disc standard, not intended for streaming).

I think when extracting the RPU and converting the profile to be 8.1 compatible that the metadata may be converted from FEL to MEL essentially, although I'm not sure on this. Also, our current displays can only display 10-bit depth.

On the gray bars on cropped video vs black bars, that is interesting and I hadn't heard that. Do you know which players are affected by this? That actually sounds more like a implementation issue with those specific players. I have not experienced this with the 2019 Shield and Plex app (which uses ExoPlayer). I always see black bars. I also would think this issue wouldn't be specific to DV encoded videos, but all encoded HDR content.

At the end of the day, I believe I'm simply converting Dual Layer profile 7 Dolby Vision to single layer while discarding the enhancement layer. The extracted/converted RPU is created from information present in both the Base Layer & Enhancement Layer tracks (MEL/FEL). Injecting the converted RPU into the encoded BL track basically gives us a BL + RPU. I interpret this to mean we now have the Base Layer (HDR10 video track) + RPU (Dynamic DV Metadata, rather than just static HDR10 Metadata). So still Dolby Vision, just not as good a Profile 7 DV. However, no big loss here as we can't currently playback the Enhancement layer on streaming devices anyway. The advantage I see here is being able to encode the video with x265 AND keep DV Dynamic metadata for playback. As mentioned above I will keep uncompressed original DV Profile 7 rips of my movies archived in case we are able to take advantage of the MEL/FEL layer during playback on streaming devices in the future.
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:
Wed Nov 24, 2021 2:57 pm
As I understand it, there aren't really any streaming players out there that are capable of playing the FEL.
Well, I have a Ugoos AM6+ which has a second hevc decoder so it can do FEL. But it's a very buggy player. I still haven't been able to play one full DV movie without stuttering and audio dropouts. Annoying as hell.
hogfan wrote:
Wed Nov 24, 2021 2:57 pm
I think when extracting the RPU and converting the profile to be 8.1 compatible that the metadata may be converted from FEL to MEL essentially, although I'm not sure on this.
Interesting, I didn't think of the 8.1 conversion this way yet.
hogfan wrote:
Wed Nov 24, 2021 2:57 pm
On the gray bars on cropped video vs black bars, that is interesting and I hadn't heard that. Do you know which players are affected by this? That actually sounds more like a implementation issue with those specific players.
Sorry, I can't remember where or for what player this was. So yes, it was for (a) specific player(s) but I am sure it had to do with Dolby Vision content being cropped.
I did so many reading on Dolby Vision and on so many different places I lost track on what was where. Should I accidentially bounce on it again, I'll let you know.
hedcase
Posts: 27
Joined: Sat May 18, 2013 7:43 pm

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

Post by hedcase »

@hogfan

I've been ripping my large 4K collection for years now and have always wanted to get DV on my Plex server. From my searches online, I've found a ton of mixed information on process which most seemed pretty complicated.

Was this just a test for you -- or are you doing more rips/encodes?

Guess my question is, is it worth going down this path and would you recommend it?
exitguy
Posts: 41
Joined: Tue Aug 11, 2020 6:10 am

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

Post by exitguy »

hedcase wrote:
Thu Dec 23, 2021 7:58 am
@hogfan
Guess my question is, is it worth going down this path and would you recommend it?
Quicker and easier to just play the disc in a DV enabled player, at least you get what the editors intended you to see.
hedcase
Posts: 27
Joined: Sat May 18, 2013 7:43 pm

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

Post by hedcase »

I figured but was still hopeful.

Is the process still relatively easy to rip to MKV (while retaining DV)? I wouldn't mind getting some remuxed copies on my server.
mtotheb
Posts: 30
Joined: Wed Jan 27, 2021 12:18 pm

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

Post by mtotheb »

Hey @hogfan
I tried replicating exactly that with a Ready Player One rip. The end .mkv basically just glitches and I think it has to do with the RPU having a different frame count than the hevc. Have you encountered a problem like this?
Shield TV 2017 -> LG DSN10YG Soundbar with SPK8 Rears -> LG B1 OLED
agneva
Posts: 61
Joined: Mon Jan 06, 2020 11:42 am

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

Post by agneva »

Hi, I riped my 4K DV FEL to mp4 and mkv.
In mkv there is one video stream including all: HDR10 + DV with RPU+FEL + HDR10+ (if available).
I checked the size to mp4 with 2 video streams: 1st: HDR10, 2nd: RPU + EL.
The size from mkv video stream is the same, that means the FEL is in the mkv (6MBit/s).
MP4 with AC3 Audio (no HD Audio) can be played from Bluray Player (LG UBK90) with FEL.
MKV is always played without DV and HD Audio is muted.

Will there be ever a player who can play the DV with FEL and HD-Audio from mkv ?
exitguy
Posts: 41
Joined: Tue Aug 11, 2020 6:10 am

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

Post by exitguy »

agneva wrote:
Mon Dec 27, 2021 8:10 am
Will there be ever a player who can play the DV with FEL and HD-Audio from mkv ?
Well it didn't come for this Xmas but maybe for the next, or next, or next .....
agneva
Posts: 61
Joined: Mon Jan 06, 2020 11:42 am

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

Post by agneva »

What about the DuneHD Players?
https://www.dune-hd.com/collections/fro ... -vision-4k
• New feature: Dolby Vision decoding and output is now supported also when playing all other popular file formats:
• MKV P7 FEL single-track (dual-layer)
• MP4 P7 FEL single-track (dual-layer)
• TS P7 MEL/FEL single-track (dual-layer)
• TS P4 MEL/FEL single-track (dual-layer)
• MP4 P7 FEL dual-track
• MP4 P7 MEL dual-track
• Dune HD media players now have the widest support for Dolby Vision file formats among all existing media players (all popular formats supported by any other media player are supported, and no other media player supports as many formats). The list of supported Dolby Vision file formats now includes:
• Blu-ray disc images:
• BDMV (Menu mode) P7 MEL/FEL
• BDMV (Lite mode) P7 MEL/FEL
• BD ISO (Menu mode) P7 MEL/FEL
• BD ISO (Lite mode) P7 MEL/FEL
• M2TS files:
• M2TS P5
• M2TS P7 MEL/FEL dual-track
• M2TS P8
• TS files:
• TS P4 MEL/FEL single-track (dual-layer)
• TS P5
• TS P7 MEL/FEL single-track (dual-layer)
• TS P8
• MKV files:
• MKV P4 MEL/FEL single-track (dual-layer)
• MKV P5
• MKV P7 MEL/FEL single-track (dual-layer)
• MKV P8
• MP4 files (this also includes MOV files):
• MP4 P4 MEL/FEL single-track (dual-layer)
• MP4 P5
• MP4 P7 MEL/FEL single-track (dual-layer)
• MP4 P7 MEL/FEL dual-track
• MP4 P8 (this includes support for iPhone Dolby Vision MOV P8.4 files)
• NOTE: In all cases, Dolby Vision extended information from the file is used and output to TV, i.e. it is a real playback of Dolby Vision video.
hogfan
Posts: 13
Joined: Sat Oct 29, 2016 3:33 am

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

Post by hogfan »

mtotheb wrote:
Fri Dec 24, 2021 2:44 pm
Hey @hogfan
I tried replicating exactly that with a Ready Player One rip. The end .mkv basically just glitches and I think it has to do with the RPU having a different frame count than the hevc. Have you encountered a problem like this?
mtotheb wrote:
Fri Dec 24, 2021 2:44 pm
Hey @hogfan
I tried replicating exactly that with a Ready Player One rip. The end .mkv basically just glitches and I think it has to do with the RPU having a different frame count than the hevc. Have you encountered a problem like this?
Ok, here's a more detailed breakdown of my workflow and some more details in regards to what you are doing, and what you will end up with following this process.

1.) Regardless of whether you are starting with a DV Profile 7 MEL or FEL title, you will end up with a DV Profile 8.1 MKV.

DV Profile 8.1 = single layer/track Dolby Vision w/the RPU interleaved into the BL track (BL + RPU)

Quality-wise, DV Profile 8.1 is equivalent to DV 7 MEL as the "Minimal Enhancement Layer" is basically just the RPU/Dynamic Metadata. DV Profile 8.1 is a single layer/track, whereas DV 7 is Dual layer/track (BL + EL + RPU). For MEL titles, the EL really just contains the RPU data (Dynamic HDR Metadata). Rather than the RPU being interleaved into the BL track as it is in DV Profile 8.1, in DV Profile 7, it's in the EL track.

NOTE: Although different formats, you can think of Dolby Vision 8.1 (BL + RPU) as comparable to HDR10+ as both are simply "Dynamic HDR Metadata", whereas plain old HDR10 has only "Static Metadata".

2.) So our goal is to take our original DV 7 file output from MakeMKV and encode the BL in x265 to reduce the size AND retain MEL equivalent Dolby Vision metadata.

3.) The first step is to open your DV 7 MKV in FastFlix, and encode it to x265. This will take some time depending on your hardware. Fastflix does not support Dolby Vision and will completely ignore the EL and RPU data. It will only see the plain old HDR data, which is exactly what we want. Make a note of whether or not you cropped the letterbox bars out when encoding with Fastflix.

4.) Once the encode completes you will have two files: Your original source DV 7 MKV file and a new encoded HDR10 only mkv file.

5.) Now use gMKVExtractGUI tool to extract all of the tracks/streams & chapters file from the new HDR10 only encoded MKV file.

6.) Now we need to extract the RPU data from our original DV 7 source MKV and convert it to be DV Profile 8.1 compatible. To do this, we'll use ffmpeg to demux the hevc video stream from our source mkv file and pipe it through dovi_tool to extract the RPU data from the EL and convert it to be DV Profile 8.1 compatible. An example command is below. IMPORTANT: If you DID NOT crop any letterbox bars when you encoded the movie in Fastflix, then remove the -c switch after the m 2 in the dovi_tool section of the command. The m 2 tells dovi_tool to convert the RPU to profile 8.1 compatible when extracting it. The -c is for crop, and sets the "active area" of the RPU to exclude the letterbox bar areas.

There are only two cases where you shouldn't use the -c switch in the command:

Case #1 - The movie is in an aspect ratio that does not have any letterbox bars, so you didn't have to crop any when encoding.
Case #2 - If you are planning to play back your encoded MKV on a hardware Bluray player, you probably don't want to crop out the letterbox bars when encoding in Fastflix. This is because most all Bluray players will play a cropped DV movie back with gray letterbox bars instead of black, which can be distracting. If you are playing back your files on a streaming player (i.e. FireTV, Shield, etc.), then this is not an issue and you will have black letterbox bars. (Supposedly, on Bluray players, Dolby Vision uses the letterbox bar areas to display subtitles, by design.)

Code: Select all

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"
4.) Once you have extracted the RPU and converted it DV 8.1 compatible, it's time to inject it into the hevc track we extracted from our Fastflix encoded MKV.

5.) Use a command like the below example to inject the RPU into the x265 encoded video track, outputting a new hevc track with the RPU data interleaved/injected:

Code: Select all

dovi_tool inject-rpu -i "D:\Rips\The Matrix (1999)\The Matrix (1999)-fastflix-26dd_track1_[und].hevc" --rpu-in "D:\Rips\The Matrix (1999)\RPU_81.bin" -o "D:\Rips\The Matrix (1999)\The Matrix (1999)-fastflix-26dd_track1_[und]_injected.hevc"
As long as you don't see any warning message about the frame counts not matching between the RPU and the hevc track you are good to go. (I've only seen this once on the movie Mad Max, and I'm looking into that one)

6.) Now that we have a new x265 encoded hevc video track with the DV profile 8.1 compatible RPU data injected, it's time to construct our new/final MKV file. Fire up the Multiplexer tab in MKVToolNix (version 63.0.0 or newer), and add the following files:

a.) Your injected hevc track (i.e The Matrix (1999)-fastflix-26dd_track1_[und]_injected.hevc
b.) The audio tracks, subtitle tracks, & chapters file you extracted earlier with gMKVExtractGUI

Give your output file a name and start multiplexing. I like to name mine like: The Matrix (1999).dv8.mkv so I can easily tell it's a DV Profile 8 movie by the file name.

7.) If you view the resulting file with the MediaInfo tool, you will see that it's DV Profile 8.

8.) Play the new MKV movie file and you should now see Dolby Vision is triggered on playback, and file you play back flawlessly................and since DV Profile 8.1 is HDR10 compatible/fallback, if you play the movie on a non-DV capable device, it will just play back in standard HDR.

There are ways to inject the RPU data into the video at encode time when encoding with x265 using other tools like StaxRip, but I find it much easier to encode with Fastflix (my encoding tool of choice for UHD content), and then inject the RPU data after encoding. It's a few more steps, but has been working very for me so far.
hogfan
Posts: 13
Joined: Sat Oct 29, 2016 3:33 am

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

Post by hogfan »

hedcase wrote:
Thu Dec 23, 2021 7:58 am
@hogfan

I've been ripping my large 4K collection for years now and have always wanted to get DV on my Plex server. From my searches online, I've found a ton of mixed information on process which most seemed pretty complicated.

Was this just a test for you -- or are you doing more rips/encodes?

Guess my question is, is it worth going down this path and would you recommend it?
I am indeed encoding all of my DV Profile 7 MKV movies to x265 and outputting DV Profile 8.1 MKV files (equivalent to MEL). The DV data does show up in Plex and the movies play back well with DV from the Plex app on my 2019 Nvidia Shield --> Yamaha A/V receiver --> LG C9 TV.

The only thing you really lose by doing this is the FEL (for movies that have it), and no streaming device is capable of playing back that additional video track reliably today. And you aren't really losing FEL if you keep a backup of your original DV 7 MKV for FEL movies.

See my updated post just above this one on my current process and workflow.
Morku
Posts: 3
Joined: Fri Jan 07, 2022 5:16 pm

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

Post by Morku »

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.
profzelonka
Posts: 1
Joined: Sun Jan 09, 2022 8:55 pm

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

Post by profzelonka »

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.)
Post Reply