quietvoid / dovi_tool

dovi_tool is a CLI tool combining multiple utilities for working with Dolby Vision.
MIT License
582 stars 57 forks source link

Creating Profile 5 output from Profile 7 input #49

Closed martinpickett closed 2 years ago

martinpickett commented 2 years ago

Apologies in advance if this is the wrong place to post this question. If you have a preferred alternative I will happily repost there.

I have a single track dual layer profile 7 Dolby Vision file (produced by MakeMKV from a UHD Blu-Ray) which I would like to convert into a profile 5 Dolby Vision file for playback on an Apple TV 4K (which officially supports only profile 5 DV files). 1) Is this theoretically possible? 2) Can dovi_tool currently do this? (If so, how?)

Caveat: I am aware an RPU can be extracted and used to transcode into profile 5 DV with x265, I am currently more interested in the possibility of converting without transcoding.

Many thanks for your help

quietvoid commented 2 years ago

It is possible in theory, but it absolutely requires transcoding because the image has to be processed. This project doesn't intend to have any image processing, so this isn't supported.

The problem with the Apple TV 4K is that it doesn't actually process the Dolby Vision metadata unless the file is true profile 5, which is inherently incompatible with profile 7 base video. So what you're attempting to do is going to playback the same as regular HDR10. There are discussions on this over at MakeMKV forums.

martinpickett commented 2 years ago

Thank you for the quick and thorough answer. Looks like I will be going the slow route with x265.

quietvoid commented 2 years ago

Maybe I wasn't clear, but by processing I meant that the image also has to be converted, because profile 5 is supposed to be a different colorspace. There's no public method for doing this.

Reencoding with x265 is not going to change anything.

martinpickett commented 2 years ago

Ok. If I understand correctly, converting from profile 7 to profile 5 requires converting between two different colourspaces (YCbCr -> ICtCp?), however the colourspace used by profile 5 is not publicly defined and therefore there is no publicly available conversion software. So my ideal situation is not possible.

The next best thing to profile 5 is profile 8 (I could replace my Apple TV 4K with an Amazon Fire TV Stick 4K). Do profile 7 and profile 8 share the same colourspace? (I assume yes, as dovi_tool seems to offer this conversion.) If, in the future, I wanted to shrink the video file by transcoding, is x265 capable of reading in either a profile 7 or profile 8 file and outputting a profile 8 file?

Thank you for your patience and knowledge.

quietvoid commented 2 years ago

Do profile 7 and profile 8 share the same colourspace?

Correct.

If, in the future, I wanted to shrink the video file by transcoding, is x265 capable of reading in either a profile 7 or profile 8 file and outputting a profile 8 file?

x265 only supports profile 8. I'm not sure there's a reliable tool to use the original profile 7 EL with a transcoded base layer.

martinpickett commented 2 years ago

Once again thank you, you have been very helpful.

akash329d commented 2 years ago

Sorry to bring this back up @quietvoid but is the only thing preventing a conversion from profile 8/7 -> 5 the conversion of the color space? I was under the impression it was generating the RPU as stated here - https://forum.makemkv.com/forum/viewtopic.php?style=6&f=12&t=18602&start=2445#p90215. Wasn't entirely sure though as I thought the RPU would be the same regardless of the DV profile (not dependent on the color space). Don't have a great understanding of this, so just wanted to try and figure out what was preventing this.

Additionally, is converting between color spaces considered transcoding? Since there wouldn't be any information loss if I'm understanding correctly?

quietvoid commented 2 years ago

but is the only thing preventing a conversion from profile 8/7 -> 5 the conversion of the color space?

No, you also need to generate reshaping metadata for profile 5. For which there is no public method.

Additionally, is converting between color spaces considered transcoding?

Of course it is transcoding, you have to modify the base video. But like I said, there's no way to even convert the colorspace properly right now.

saindriches commented 2 years ago

The RPU between profiles 5 and others are different mainly because of the composer metadata (the reshaping or NLQ part). Profile 5 uses IPT color space and reshaping to use more code words in encoding, and this ensure less quantization error than straight encoding (compared with HDR10 compatible base layer, like 7 and 8.1). THe most important part in this process is to determine the reshaping function for each frame (or scene). No public method yet.

You CAN refer to the decoding process of profile 5 and manually do a inverted process: For example, convert a normal video to IPT (needs transcoding), and generate a simple reshaping function y = x for it (which means no reshaping actually). But I don't think you will get much benefit from it.

akash329d commented 2 years ago

You CAN refer to the decoding process of profile 5 and manually do a inverted process: For example, convert a normal video to IPT (needs transcoding), and generate a simple reshaping function y = x for it (which means no reshaping actually). But I don't think you will get much benefit from it.

Makes sense, thanks both of you for the quick replies! Was really just trying to find out if it would be possible to convert profile 7/8 into 5 so that it's playable on iOS/macOS. Seems like this is possible w/ transcoding based on your reply. Edit: But seems like this will have no benefit over just playing a normal HDR video, since you won't get the dynamic metadata (as it seems like the reshaping function changing is what provides that), so it would basically just be normal SDR at that point if the reshaping function is x=y? (As a side note, are there any good white papers for this info? Seems like I'm missing a lot of the basic knowledge).

quietvoid commented 2 years ago

so it would basically just be normal SDR at that point if the reshaping function is x=y

Since the input is PQ coded, this is effectively just an identity transfer function, which leaves the output in PQ. The whole point of reshaping is to optimize the encoding, because PQ makes it complicated to allocate bits in a good way.

And the IPT part supposedly improves the color precision even when encoded in 10 bit.

There are multiple patents on IPT PQ, and papers such as here: https://res-www.zte.com.cn/mediares/magazine/publication/com_en/article/201601/448972/P020160311294995790791.pdf

akash329d commented 2 years ago

I see, so then if I’m understanding correctly, it should be possible to convert profile 8 into a profile 5 video without quality loss if it was possible to convert to the color space correctly? You wouldn’t get the reshaping benefits and would have to use an identity transfer function but profile 7/8 don’t have that anyway right?

quietvoid commented 2 years ago

I guess so, there's just not much point in doing that.

akash329d commented 2 years ago

I guess so, there's just not much point in doing that.

Yeah I guess that's true. Probably better off just waiting for a player to support profile 7/8 directly rather than trying to convert it to profile 5. Regardless, I now have a better understanding of the differences between the profiles, so thanks for the info.

zimq commented 11 months ago

now that profile 8 cannot be transferred to 5 due to different colourspaces, why profile 8 to 5 is possible via this tool, and this procedure even add hdr10 info to the base layer.