Darktable: Converting CR2 to BT2020 PQ AVIF: Works but how to do it correctly?

Hi,

I’m new to Darktable and somewhat to the whole topic, so I don’t mind thorough explanations. I tried to search for the same but didn’t find exactly the same topic. If my questions are covered even partly in some other thread, please do point me to it.

HDR movies have much more real-looking colors compared to SDR content so I wanted to experiment on how RAW photos from my PowerShot could look on an HDR TV. After plenty of trials and errors, I can now get a BT2020 PQ image in HDR mode on my TV using a self-made app running on an Android TV device.

I’m currently setting BT2020 PQ in the “input profile” as the “working profile”. Is that the right approach? With that the photo on my TV is way too bright. I can use the “exposure” or “filmic rgb” modules to darken it by blindly tuning the EV values but then I can see barely anything on my SDR monitor where I’m running Darktable.

Is there by any chance any guides or rule of thumbs to explain what modules I should use and with what settings to get a roughly correct looking photo?

Thanks

1 Like

It is not correct as the input profile and probably isn’t good as a working profile.

You should set it as your output profile and softproof profile tho.

1 Like

An app that can display BT.2020 + PQ or HLG stills on an ATV device would be a wonderful thing to have.

Right now I have to encode any HDR image to an H.265 video. I find HLG to be a bit easier since it only needs the Alternate Transfer Curve metadata, which is a gigantic pain in the ****

A few people on Pixls have had significant success doing what you describe (in my case using the JPEG XL format and BT.2020 + PQ) however there is still a bit of tinkering involved. AVIF output also works, but on my Darktable build it takes a lot of time to produce the file (~1 minute/picture).

Using some “PQ” preset, I have set up a workflow that allows me to get good-looking HDR stills while spending around a minute per picture.

Earlier versions of my workflow are described in these two threads:

Although I have linked to specific posts, the two threads contain lots of relevant information, and they are must-reads if you are interested in making HDR stills using Darktable.

Note, however, that due to some changes in Darktable, some of the instructions are outdated. For instance, you will need to apply an exposure compensation of log2(203 nits /10000 nits) ≈ -5.622 EV at the end of the pipeline if you use the PQ curve (this will make the preview very dark, as you observed). My preset automatically sets an “exposure 1” module with this correction around the end of the pipeline, but I temporarily disable it while performing the other adjustments (I focus on the midtones to set the exposure, letting the highlights clip in the preview). This is suboptimal, but until we get a proper HDR preview, this will have to do the job.

Here is a (non-exhaustive) list on known-working modules:

Expand modules

And the export settings for AVIF (I haven’t tuned the quality here because I usually export to JXL instead):

Expand export settings

image

Finally, I use Adobe’s Gain Map demo app to view the HDR files on a M1 MacBook Pro. In my experience, this is currently the best HDR image viewer for this platform.

I should probably update the tutorial at some point, or maybe turn it into a short video. A few rainy weekends could come in handy…

2 Likes

JLTastet, thanks a lot for the comprehensive explanation. I’m new to Darktable but now I have my own preset with e.g. the exposure module duplicated for the “PQ effect” to toggle it on/off during the editing.

You module list above has several modules that aren’t in the older posts. If you would have time to explain how you use each of them in a bit more detail, I would really appreciate. For now my image is still quite quite “flat” and a bit too bright compared to the camera’s jpgs and I’m assuming I still have some basic settings wrong there.

It’s of course possible that my own AVIF viewer app isn’t doing everything correctly either. But at least with some random images that I downloaded, it might be showing them at least roughly correctly. Especially I’m a bit puzzled what metadata (min/max luminance, MaxCLL/MaxFALL) to provide to the TV together with my AVIF. I’ve tried bunch of different values but I don’t really see a difference.

And it’s quite inconvenient for me to edit as well as I run Darktable on my Linux with a SDR monitor (technically the monitor is HDR but I don’t think there’s anything in Linux yet to see HDR), then copy the final AVIF to the Android TV device and launch my viewer app there.

By any chance is it open source?

I’d find such an app very useful.

I’ll try to write a longer post later, but here is already a quick description of the modules that I typically use. If you are interested, I also posted some HDR edit (with the XMP) in this Play Raw.

Here is the style file I currently start from: Default PQ v2.dtstyle (4.5 KB)
After applying it, I’ll disable all the modules above (and including) exposure·1, edit the midtones, then reapply the modules one-by-one from bottom to top.

The most relevant modules here are:

  • highlight reconstruction: Set to “reconstruct in LCh” to ensure that any RAW clipping smoothly fades to white (the default “inpaint opposed” makes it look magenta and works best if filmic rgb is used later.
  • exposure: To adjust the exposure of the midtones, using the white frame as reference (light bulb on the bottom right). Expose as usual, with midtones around 18% grey, but ignore the highlights at this stage.
  • rgb curve: I apply some “foot” / shadow roll-off in order to recover contrasty, deep blacks in the shadows, that usually contain a significant amount of noise — forming some “veil” even after noise reduction — because I exposed for the highlights. This has to be adjusted for each scene, usually by eye, zooming in some dark area. The upper part of the curve is linear so that I don’t mess with the contrast in midtones and highlights.
RGB curve example

image

  • exposure·1: The -5.622 EV “PQ scaling”.
  • tone equalizer: I sometimes use more than one tone equalizer module (one for midtones and one for highlights). Since this one is after the PQ scaling, I use it to darken the strongest (and sometimes distracting) highlights, so that they stay within 2 or 3 EVs of HDR overrange. Here, I use an external viewer to assess the result.
  • base curve: A predefined curve that is linear in the SDR range but then smoothly rolls-off the highlights, up to some predefined brightness (here 1600 nits or 16% of the PQ range). This is mostly to ensure that even the strongest specular highlights are mapped to reasonable values.

The other modules aren’t really specific to HDR:

  • white balance & color calibration: Used for white balancing. Either to fine-tune the camera-chosen white balance, or to set it manually (necessary if, for instance, I used UniWB to precisely expose to the right).
  • lens correction, orientation and diffuse or sharpen: Mainly corrective modules. For the latter, I use the “sharpen demosaicing: AA filter” preset because my camera has an AA filter.
  • astrophoto denoise: The noise reduction algorithm that looks best to my eye. I usually don’t try to reduce luma noise because I prefer some “grain” to losing details, so I set chroma to 100% and just tune the strength parameter. But this is really a matter of taste.

Feel free to post your AVIF files here (zipped because otherwise Discuss will refuse them), so I can have a look at them with the Adobe viewer (which is more-or-less the reference implementation for those HDR and gain map standards).

Yep, HDR editing is still a bit experimental and hacky, unless you use one of the few commercial apps that supports it… Hopefully the situation will eventually improve, even on Linux, thanks to the current standardisation efforts and the push from some large industry players :crossed_fingers:

2 Likes