Open ggarra13 opened 1 month ago
Hi Gonzalo, before diving into discussing code, could you please let us know:
Some of the stuff you are doing in your code is not necessary since OCIO already has built-in transforms that could be used. However, OCIO does not currently have specific HDR to SDR conversion options, so that part would need to be more bespoke. Depending on whether you need local tone-mapping or some proprietary algorithm such as Dolby Vision, it may or may not be possible to do that part in OCIO. There are LUTs available for licensing from various places that could be applied using OCIO. There are so many options, I'm not sure what the best published algorithm to recommend currently is, if you're looking to implement it yourself.
Thanks Doug. I'll try to answer the best I can.
The movie files in question are:
HDR: https://mega.nz/file/iGgxXLjL#gEsU5XGQNgRkXgWEbhqm0tZyD9azoY1T6YhqNi35OYI
SDR: https://mega.nz/file/jKYzUIZC#Nz34EVAv3SDPwu1atsTPvL-MdSSXPutTxmL5ikC3SZg
Here's a snapshot of all the HDR info I can get from FFmpeg:
Side data:
Mastering Display Metadata, has_primaries:1 has_luminance:1 r(0.6800,0.3200) g(0.2650,0.6900) b(0.1500 0.0600) wp(0.3127, 0.3290) min_luminance=0.000100, max_luminance=1000.000000
Note that that metadata is for the stream. The movie in question also has frame HDR metadata which is:
- What non-linearity is used to encode your input (ST-2084/PQ?)?
Not sure.
- Do you really need to support "custom primaries" for HDR video from ffmpeg? I would guess that there are really only three sets of primaries that are likely (Rec.709, P3-D65, and Rec.2020). OCIO has built-in conversions for those, so you may want to just check to see which one it is rather than supporting arbitrary possibilities.
Ideally, yes, as FFmpeg's metadata in v7.0 now can change from frame to frame.
- What color space do you need to output (Rec.709?)?
Rec.709, indeed.
- What kind of HDR to SDR conversion do you think your users want?
For this example, one that matches Apple's videotoolbox more closely.
In a perfect world, I was shooting for ACES HDR to SDR conversion, as that should be the best one, so that even if it does not match exactly it would be the superior algorithm and hopefully the differences should be minimum.
I couldn't open the files you posted, but the Mastering Display Metadata is a description of the color gamut and dynamic range of the display the content was color graded on. It is not necessarily an indication of the color space that the movie is encoded in for transport. For example, the grading monitor typically has a P3 gamut but an HDR movie would typically be transported using Rec.2100 (HLG or PQ), which uses the Rec.2020 gamut. In short, you should not be converting color spaces based on that metadata. It is just info that might be useful for tone or gamut mapping, to know the extent of the source content.
Please keep in mind that ACES does not offer HDR to SDR conversion, per se. What it offers is a set of Output Transforms that convert scene-referred source data to various displays, both HDR and SDR. Yes, because the transforms may be applied in the inverse direction, you could convert HDR back to ACES2065-1 through one transform and then forward through an SDR transform. But in practice, I've not heard of anyone doing that.
First, let me say that color science is not my area of expertise (neither is math !!! :)
One of my mrv2 users pointed out that my viewer is not handling HDR to SDR conversions properly. I am reading the FFmpeg metadata of the .mp4 file and trying to apply it to an OCIO pipeline.
Now I am trying to get a pipeline that works for OCIO2. I am trying to avoid using another library like libplacebo or similar.
This is what I have so far: