1
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.
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:
However, if I then convert the image using imagemagick from PNG to JPEG, the colors completely change.
convert output.png output.jpg
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
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.
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 – 2019-07-30T06:05:13.483I'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 – 2019-07-30T06:06:39.880
“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 – 2019-07-30T15:00:20.553Use this more correct command instead: zscale=transfer=linear,tonemap=hable,zscale=transfer=bt709,format=gbrp – Paul B. Mahol – 2019-08-01T08:40:30.487