3 ms·
I always prefer ffmpeg to HandBrake, except when working on HDR videos. I couldn't find a proper ffmpeg command to copy the HDR metadata from input source to o
by beltsazar 3y ago
I always prefer ffmpeg to HandBrake, except when working on HDR videos.
I couldn't find a proper ffmpeg command to copy the HDR metadata from input source to output. Last time I checked it was not possible. I needed to extract the metadata manually (e.g. using MediaInfo), then pass each metadatum as an argument for ffmpeg.
Does anyone know if it's still the case?
- gcr 3y agoYeah, 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-ffmpeg/ 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.html https://x265.readthedocs.io/en/master/cli.html The 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-using-ffmpeg-while-maintaining-selected-auio-tracks-intact-from-source-d1e2f6a16162 https://medium.com/@yllanos/how-to-encode-a-4k-hdr-movie-usi... and https://codecalamity.com/encoding-uhd-4k-hdr10-videos-with-ffmpeg/ 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_encode_4k_hdr_video_as_h265_with_ffmpeg/ 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_convert_dolby_vision_hdr_to_hdr10/ 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_user/ https://www.reddit.com/r/ffmpeg/comments/a32yv4/deleted_by_u...
- Jiocus 3y agoHave you tried -movflags and use_metadata_tags? ffmpeg -i $input_file -movflags use_metadata_tags -crf 22 $output_file Source: https://video.stackexchange.com/a/26076 https://video.stackexchange.com/a/26076