Yeah, I think you still need to extract the metadata yourself and supply it manually.
To elaborate---and you already know this, but for the benefit of others---there are two common HDR video standards: Dolby Vision and HDR10. Both require custom support within the encoder (eg this is more of a libx265 thing, less of a libavformat/ffmpeg thing).
Fortunately, if your source video is HDR10, that means you can extract the global (unchanging) transfer functions and tone mapping and apply them yourself to the output metadata. FFmpeg can supply this to the encoder, but it doesn't copy it from the source to the destination by default. Here's an article that describes how to do this: https://codecalamity.com/encoding-uhd-4k-hdr10-videos-with-f...
I've been able to reencode one HDR10-encoded video from one format to another while preserving the metadata, the final command from my shell history was something like:
ffmpeg -i Movie-with-HDR.mkv -c:v libx265 -map_metadata:s:0 0:s:0 -map_metadata:g:0 0 -x265-params crf=21:master-display="G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,50)":max-cll=1000,240 Movie-output.mkv
where the `master-display` and `max-cll` settings are the color transfer functions from the first video that I had to extract from some other tool. These settings are documented in the libx265 parameters:
https://x265.readthedocs.io/en/master/cli.htmlThe process for Dolby Vision is harder. Since that metadata is dynamic, I'm not sure how one could get it from the source, but it can be supplied to libx265 through a command line argument. Unfortunately, it's only exposed through the command line and isn't available to the API, so ffmpeg can't do this for you yet.
Other references:
- On the process of extracting the proper transfer functions and supplying them to ffmpeg: https://medium.com/@yllanos/how-to-encode-a-4k-hdr-movie-usi... and https://codecalamity.com/encoding-uhd-4k-hdr10-videos-with-f...
- A bunch of folks working together to do same: https://www.reddit.com/r/ffmpeg/comments/g3uucr/how_do_i_enc...
- On converting from dolby vision to HDR10, HLG vs PQ, https://www.reddit.com/r/ffmpeg/comments/nkxbay/how_to_conve...
- On subtleties of dolby vision: https://www.reddit.com/r/ffmpeg/comments/a32yv4/deleted_by_u...