3

I have a source video that is a UHD HDR MKV file using the HEVC codec. Specifically, the input video stream as reported by ffprobe is:

hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x2160 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)

I'm trying to take snapshots of it - extract single frames at specific times. Naively, I start with this: (the -ss time is just an example)

ffmpeg -ss 00:01:02 -i input.mkv -vframes 1 output.png

This "works", but results in washed out colors, because the original is HDR and my iMac monitor isn't.

Frame extracted with no tone mapping

OK, so I enable the tone mapping filter like so:

ffmpeg -ss 00:01:02 -i input.mkv -vf "zscale=transfer=linear,tonemap=hable,zscale=transfer=bt709" -vframes 1 output.png

This also appears to work, giving an extremely accurate looking result:

Frame extracted to PNG with tone mapping

However, if I then convert the image using imagemagick from PNG to JPEG, the colors completely change.

convert output.png output.jpg

Tone mapped image converted to JPEG

The image is still brighter than the un-tone-mapped original, but the color improvements have been lost. The image is washed out again.

Why?

Weirdly, and frustratingly, if I use ffmpeg to convert to BMP in the first place, instead of PNG, I get yet a third different result, with partially improved colors, but not as good as the PNG result, although the BMP file does convert to JPEG without the colors being further altered.

ffmpeg -ss 00:01:02 -i input.mkv -vf "zscale=transfer=linear,tonemap=hable,zscale=transfer=bt709" -vframes 1 output.bmp

Frame extracted to BMP with tone mapping

What's going on?

I did note that the PNG uses 16-bit color channels, and not 8-bit:

identify output.png 

output.png PNG 3840x2160 3840x2160+0+0 16-bit RGB 24.2MB 0.000u 0:00.000

I did try appending "format=rgb24" onto the end of the filter string to create an 8-bit channel PNG, which did work, but the results remain visually identical as above.

4
  • There's some ambiguity here - how does the result of ffmpeg look, without further processing by other tools? - You mention the PNG output is "extremely accurate looking result". How about the BMP? Share the log of ffmpeg -i output.png -i output.bmp?
    – Gyan
    Commented Jul 30, 2019 at 6:05
  • I'm not sure I understand your request. What do you mean by "the result of ffmpeg"? Why would I convert the PNG to BMP using ffmpeg? I do acknowledge that "accuracy" is subjective as I am tone mapping an HDR source to an SDR result, but that should be irrelevant to the fact that converting the resulting PNG to JPG with imagemagick changes the colors, or that making a BMP instead results in different colors.
    – David
    Commented Jul 30, 2019 at 6:06
  • “Why would I convert the PNG to BMP using ffmpeg?” – you wouldn't. Gyan just wants to see some info about the files. Notice the two -i options. I guess that the actual question is: What do you really want do do? Do you need JPEGs in the end?
    – slhck
    Commented Jul 30, 2019 at 15:00
  • Use this more correct command instead: zscale=transfer=linear,tonemap=hable,zscale=transfer=bt709,format=gbrp
    – user564335
    Commented Aug 1, 2019 at 8:40

1 Answer 1

0

Try

zscale=t=linear,tonemap=hable,zscale=p=709:t=709:m=709
1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Sep 6, 2022 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .