Authoring Dolby Vision compatible/compliant mp4 files for HTPC/Media Server Updated 05/01/2022

staknhalo

Supreme [H]ardness
Joined
Jun 11, 2007
Messages
6,924
I posted this elsewhere, figured maybe some people here might be able to use this though.

I fucking hate Dolby Vision. It's pretty as hell, but it fragmented this video generation so much and even fragmented itself within the fragmentation it caused. And it's a proprietary color space. But it can't be out there and I not have it.

Anyway, here's the tools I use to author Dolby Vision files for archiving (mainly my own Dolby Vision UHD rips from purchased discs that then serve as the 1:1 hard backup) on Windows.

You need to have some knowledge of command line, and muxing video/audio streams. Also gonna have to use a hex editor at one point.

These are all freely available, gathered from the makemkv forums, and github, links provided. I'll post the readme's I made for myself for each tool to give you an idea of what they do, how to use them, what is possible. This is also helpful if you want to just mux in separate (better) audio streams, or encode the base HDR10 layer to save some space over a 1:1 copy.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
quietvoid's Dovi_Tool 1.5.0 (from github: Releases · quietvoid/dovi_tool )
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Tool allows for various things with Dolby Vision files from muxing DV7 FEL streams into a single layer stream, to turning DV7 FEL/MEL dual streams to DV8.1 RPU only single stream, as well as extract and convert DV5 RPU into DV8.1 RPU format to allow creation of DV8.1 files from DV5 files.

Command 1: 'dovi_tool -m 2 extract-rpu Video2.hevc' (extracts RPU metadata from p7 FEL/MEL and converts it over to p8 RPU metadata format)

Command 1a*: 'dovi_tool -m 3 extract-rpu Video2.hevc' (extracts RPU metadata from p5 file and converts it to p8 RPU metadata format)

Command 2: 'dovi_tool.exe inject-rpu --input Video1.hevc --rpu-in RPU.bin' (Injects RPU metadata in p8 format that was converted from p7 into HDR10 BL turning it into single layer Dolby Vision 8 RPU + HDR10 BL stream)

Command 2a: 'dovi_tool -m 1 extract-rpu Video1.hevc' (For extracting self-made Dolby Vision 8 single stream made from Dolby Vision 7 MEL RPU and converting back into Dolby Vision 7 MEL RPU - process is lossless both ways - requires dovi_Tool 1.2.1 minimum)

Command 3**: 'dovi_tool mux --bl Video1.hevc --el Video2.hevc' (For muxing p7 FEL video stream into HDR10 BL video stream, creating an individual dual-track single-layer/DTSL p7 FEL stream - requires dovi_Tool 1.5.0 minimum)

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
quietvoid's HDR10Plus_Tool 1.0.0 (from github: Releases · quietvoid/hdr10plus_tool )
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Extract or inject HDR10+ metadata into HEVC stream (Handbrake strips/removes HDR10+ metadata when encoding - so to shrink HDR10+ files first extract the metadata, then encode the file, then re-inject the metadata)

Command 1: 'hdr10plus_tool extract Video.hevc -o Metadata.json' (extracts HDR10+ metadata and saves to .json file)

Command 2: 'hdr10plus_tool inject -i Video.hevc -j Metadata.json -o VideoPLUS.hevc' (injects HDR10+ metadata into HEVC stream)

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Turn HDR10+ metadata into Dolby Vision metadata***
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Command 1: 'hdr10plus_tool extract Video.hevc -o Metadata.json' (Extracts HDR10+ metadata and saves to .json file)

>>Next commands go through Dovi_Tool and v0.5.0 minimum required<<<

Command 2: 'dovi_tool generate -j Extra.json --hdr10plus-json Metadata.json --rpu-out RPUPlus.bin' (combines metadata from edited 'Extra.json' - template is below and you need to do one for every title specifically - and metadata from extracted 'Metadata.json' and combines+converts them into p8 RPU metadata format)

Command 3: 'dovi_tool.exe inject-rpu --input Video.hevc --rpu-in RPUPlus.bin' (Injects HDR10+ generated RPU metadata into HEVC stream turning it into single layer Dolby Vision 8 stream)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Blank Template for 'Extra.json'
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{
"length": (title specific framelength here without parenthesis),
"level2": [
{
"target_nits": 100
},
{
"target_nits": 600
},
{
"target_nits": 1000
},
{
"target_nits": 2000
}
],
"level6": {
"max_display_mastering_luminance": (title specific metadata info here without parenthesis),
"min_display_mastering_luminance": (title specific metadata info here without parenthesis),
"max_content_light_level": (title specific metadata info here without parenthesis),
"max_frame_average_light_level": (title specific metadata info here without parenthesis)
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Dolby Laboratories' Dolby Vision MP4 streaming muxer (from github: GitHub - DolbyLaboratories/dlb_mp4base: The Dolby MP4 streaming muxer (dlb_mp4base) is a software implementation of a muxer of fragmented or unfragmented ISO base media file format (mp4). It supports muxing of Dolby Digital (AC-3), Dolby Digital Plus (E-AC-3), and Dolby AC-4 audio formats as well as Dolby Vision. )
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Mux DV5 or DV8 single streams or base HDR10 stream and DV7 second stream along with audio stream into Dolby Vision compatible mp4 file

Dolby Vision Profile 5 Command: - 'mp4muxer --dv-profile 5 --input-file Video.hevc --input-file Audio.aac --media-lang eng --output-file FILENAME.mp4'

Dolby Vision Profile 7 Dual-Layer Dual-Track Command - 'mp4muxer --dv-profile 7 --input-file Video1.hevc --input-file Video2.hevc --input-file Audio.aac --media-lang eng --output-file FILENAME.mp4'

Dolby Vision Profile 7 Single-Layer Dual-Track Command - 'mp4muxer --dv-profile 7 --input-file Video.hevc --input-file Audio.aac --media-lang eng --output-file FILENAME.mp4'

Dolby Vision Profile 8 Command - 'mp4muxer --dv-profile 8 --dv-bl-compatible-id 1 --input-file Video.hevc --input-file Audio.aac --media-lang eng --output-file FILENAME.mp4'

Important: Dolby Muxer has a bug where it does not apply 'dvhe' Codec ID to resulting mp4 files. This only applies to DV7 and DV8 made files. DV5 files output correctly.

After Dolby Vision mp4 mux is complete, open resulting mp4 file in hex editor. Search for 'hev1'

In a DV7 file in 'dual-layer dual-track' format, there will be 2 'hev1' entries, one for each video stream in the mp4. Change the second 'hev1' entry in the DV7 file (the actual Dolby Vision stream) to 'dvhe'.

In a DV8 file or a a DV7 file in 'single-layer dual-track' format there will only be 1 'hev1' entry. Change that to 'dvhe'

After saving, final mp4 should now be fully Dolby Vision compatible.

🙃🔫

Edit 01/09/2022 : per @gacopl mp4box has been updated to allow adding/changing codec ID to 'dvhe' without hex editing, see git post here for info and command/switch examples: Dolby Vision muxing support? · Issue #1991 · gpac/gpac

'F' key/switch before the profile is the new command for 'dvhe' output:

MP4Box -add source.hvc:dv-profile=f8.1:xps_inband -new res.mp4

will give dvhe

and

MP4Box -add source.hvc:dv-profile=8.1:xps_inband -new res.mp4

will give hev1




-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Also, if you're unaware of different Dolby Vision profile levels, here: https://www.diversifiedvideosolutio...on_profiles_and_levels-Dolby_Laboratories.pdf

And see about encoding p8 HDR/SDR BL or DV p5 colorspace + injecting RPU for p5 or p8 at time of encode using Staxrip here: Encoding Dolby Vision with StaxRip using x265 · staxrip/staxrip Wiki
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

*About 'Dovi_Tool Command 1a'

Dovi_Tool can now extract RPU metadata from a p5 DV file and convert it to p8 RPU metadata format. A scenario you would want to do this is let's say you have a Russian spy comic book movie or a different movie about a man dressed as a bat fighting a flying god-like alien - and you have either of those in a profile 5 DV file, and a UHD of that same title, so in a much higher bitrate... but only in HDR10 on UHD no DV in the UHD release (and frames/timing lines up perfectly - they need to, even if you gotta edit the UHD HDR10 file yourself to line up with the p5 DV file - if you screw up, you'll find out when watching if your messed up files makes it that far). Then this is the closest way you can have your cake and eat it too.

The Dolby Vision 5 color space isn't full 12bit color like FEL Dolby Vision is (even though everyone can't see it yet on our 10bit displays - you scrubs) it's still just 10bit but due to proprietary Dolby encoding efficiency/properties is more akin to 11bit/11.5bit color when watching back on a 12bit display, so it is technically better than just HDR's 10bit color. But it also only has DV RPU brightness effects then along with that better color, it has no DVp7 FEL added textures/effects - that stuff is exclusive to p7 FEL files/playback - so you have to decide before bothering to make this if you want to sacrifice better color in the future for higher bitrate now or just go get the storage to keep both p5 and p8 made from p5 and whatever else if you want.

**About 'Dovi_Tool Command 3'

As of v1.5.0 Dovi_Tool can now mux together a FEL enhancement layer and HDR10 base layer from dual-track dual-layer as found on disc into a singular dual-track single-layer FEL HEVC stream. This replaces the functionality of yusesope's Tool and as it's no longer required, references/descriptions/commands have been removed.

***About 'Turn HDR10+ metadata into Dolby Vision metadata'

It's only for the metadata that is cross-compatible between the two (not all is, and some is ok not exact but close enough it's usable)

Will be closer in resulting PQ to an actual DV file than just a native HDR10 only file but is a bit darker than native DV titles - a movie about an Amazon in 1984 is the best title to use for testing this - because such a movie might be available in DV5 for you to compare against its UHD which has HDR10, HDR10+ and DV7 MEL (and DV8 that you can make from the DV7) for comparison of all the different formats you're converting between each other natively or natively as can be. The resulting DV8 from HDR10+ will 'generally' look as good to you however you yourself perceive native DV 5/8 vs native HDR10 content.

Oh, and in case you guys want some various mp4 DV and other HDR test files, here (thanks to RESET_9999 and @quietvoid and whoever the hell else posted these @makemkv one by one - I can't remember if there's anything wrong with the 'Black Level' test files, and I'm not going through all 8,000 pages again over there to find out - so trust the accuracy of those ones at your own risk or whatever):

https://mega.nz/file/VSYQHLaT#KrMwvoO46sUZOAh_HrM7zQf0CSsUcjOE7ej9gTN2P7o


View attachment 3221844
1641858650981.png


Also see:
There's a script tool someone made and regularly updates that automates a lot of the processes here including skipping the extra json configuration. I've been using it lately and it works perfect so far!

[DDVT Tool] Dolby Vision RPU Demuxing / Injecting / Editing
https://forum.doom9.org/showthread.php?t=183479

New tool to convert Dolby Vision mkv (Profile 4, 5 , 7 SL, 7 DL, 8) to mp4 (DV4, DV5, DV8) from @gacopl:
gacpol said:
Hi i have something to share

I am owner of LG CX and C8 models and also nvidia shield.
I made numerous conversions to make sure what is best, i found that for those LG models most reliable is mp4, m2ts is somewhat ok but for me had seeking issues at least with emby. I have found its best to convert to proper mp4 and keep Atmos and other tracks for safekeeping to be able to remux to mkv in future once at least nvidia shield plays correctly (it does not due to colors issues etc). I have found for best results is to play mp4 directly on Emby app on LG

I have created bash script that automates authoring and conversion of different Dolby Vision mkvs to mp4 that will work on above LG models without issues, so far i have converted around 30 releases no issues to the point i automated workflow

So my tool converts whatever mkv you throw at it to mp4 with DV4,5 or 8 with EAC3 audio and keeps original truehd atmos etc alongside for future, i have tested and remuxing with mkvtoolnix makes it playable with atmos again on nvidia shield no issues.

It automates ffmpeg dovi_tool and mp4box workflow and try to use as little drive space as possible thanks to linux pipes. I have it running on my NAS and is chugging along fine

GitHub - gacopl/dvmkv2mp4: Convert any Dolby Vision profile MKV to MP4 that runs on many devices

Take a look comment, or contribute
 
Last edited:
Bump: 10/06/2021 - Updated post with new tools/features to deal with HDR10+ metadata as well as convert HDR10+ to DV - and documented new features in Dovi_Tool about making DV 8 from HDR10 only UHD + DV5 file
 
Bump: 01/09/2022 - Guide has been updated with new commands and tool info, such as conversion from p7 MEL to self-made p8 and back to p7 MEL all lossless, and info about mp4box being updated with 'dvhe' codec ID support
 
I still don't understand everything but maybe you can point me in the right direction. How can I demux a dv (profile7 ?) mkv file then mux it back into a profile 7 mp4 file? The reason I am not doing a profile 8 is because my TV doesn't support it. Thanks.
 
I still don't understand everything but maybe you can point me in the right direction. How can I demux a dv (profile7 ?) mkv file then mux it back into a profile 7 mp4 file? The reason I am not doing a profile 8 is because my TV doesn't support it. Thanks.

demux with nightly ts muxer build then run this command with dolby muxer just changed for your file name/audio type:

mp4muxer --dv-profile 7 --input-file Video.hevc --input-file Audio.aac --media-lang eng --output-file FILENAME.mp4

then do the hex edit part
 
demux with nightly ts muxer build then run this command with dolby muxer just changed for your file name/audio type:

mp4muxer --dv-profile 7 --input-file Video.hevc --input-file Audio.aac --media-lang eng --output-file FILENAME.mp4

then do the hex edit part
I should have mentioned I am trying to keep it as dual layer. I actually did use the demux script you linked and tried to run
mp4muxer --dv-profile 7 -i .\BL.hevc -i .\EL_RPU.hevc -i .\audio.ec3 --media-lang eng -o final.mp4
But it just completes immediately with a 0kb output.
 
But it just completes immediately with a 0kb output.

That means your input (hevc and/or audio) file is bad

If you're trying to keep it p7 dual layer, you have to demux the mkv into its hevc stream and audio stream with ts muxer, then run that single output hevc stream through yusesope's Tool with the demux option - that will split the single hevc back into both a BL and EL hevc stream - and then run those two hevc streams and the audio stream through mp4muxer with:

mp4muxer --dv-profile 7 --input-file Video1.hevc --input-file Video2.hevc --input-file Audio.aac --media-lang eng --output-file FILENAME.mp4

'Video1' is the BL and 'Video2' would the the DV EL in the command above

Then the hex edit

But that's what you were doing based on the command you posted

If this is FEL DV p7 and you encoded the BL at all, that could be why it's spitting out an error immediately - audio aside, FEL video needs to be kept untouched and only remuxed (making both hevc streams SL from DL is fine but that's it)- if it's MEL you should be able to encode the BL, but I convert all my MEL to p8 anyway so I'm not sure if that has the same issues as trying to make a p7 FEL encoded BL DV file

Alternatively, try remuxing right from the discs' m2ts files into the hevc/audio streams and then mux to mp4 from there, bypassing mkv altogether - possible something got screwed up along the way, so try that to eliminate as much unneeded stuff as possible
 
Last edited:
is this just for encoding files to play on a device/tv or have you found a way to play dv files in windows?
 
is this just for encoding files to play on a device/tv or have you found a way to play dv files in windows?

You can play only DV p5 and DV p8 on Windows in mp4 container only and only via supported Windows Store apps

It has color accuracy problems though for 'Home Theater Enthusiast' viewing, and is its own weird exclusive DV playback mode/type - but you will get RPU processing/displaying/effects for p5 and p8, along with 'proper' color space playback for p5 files

See this thread and my reply (3rd down) for more info and plugins needed

https://hardforum.com/threads/dolby-vision-in-windows.2014496/

This is how I verify my DV files were created properly on Windows myself (no flashing from misaligned RPU, etc) after doing all the crap in this guide I posted here
 
Last edited:
You can play only DV p5 and DV p8 on Windows in mp4 container only and only via supported Windows Store apps

It has color accuracy problems though for 'Home Theater Enthusiast' viewing, and is its own weird exclusive DV playback mode/type - but you will get RPU processing/displaying/effects for p5 and p8, along with 'proper' color space playback for p5 files

See this thread and my reply (3rd down) for more info and plugins needed

https://hardforum.com/threads/dolby-vision-in-windows.2014496/

This is how I verify my DV files were created properly on Windows myself (no flashing from misaligned RPU, etc) after doing all the crap in this guide I posted here
thnx. apparently i stopped getting or missed notifications on that thread...
 
Update 05/01/2022 yusesope's Tool is now pretty much obsoleted by the new Dovi_tool - guide updated to reflect this
 
Back
Top