Opened 2 years ago

Last modified 6 months ago

#10000 open defect

PNG produced from BT.709 video should be tagged as gAMA 2.4

Reported by: Balling Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

EOTF of BT.709 OETF is 2.4 gamma, not 2.2 gamma (Chrome hack) and not what it is now, 1.961 gamma, that is what OETF is. Gamma chunk in PNG signals EOTF, not like in JPEG XL that signals OETF or in AVIF.

Change History (9)

comment:1 by Carl Eugen Hoyos, 2 years ago

Resolution: needs_more_info
Status: newclosed

comment:2 by Carl Eugen Hoyos, 2 years ago

Component: ffmpegundetermined

comment:4 by Balling, 23 months ago

Oh, of course. Mastering is what is outside of gamut, cHRM is just primaries. How did I not complain about it? Ha.

https://patchwork.ffmpeg.org/project/ffmpeg/patch/20230117185051.475157-2-leo.izen@gmail.com/

2548c32cc10f256cc0ff90457631ef7ef94070af GENIUS!!

If before we had

color_range=pc
color_space=unknown
color_primaries=unknown
color_transfer=unknown
chroma_location=unspecified
TAG:gamma=45455/100000
[/FRAME]

now we have sRGB overwriting gamma as it should and

color_range=pc
color_space=gbr
color_primaries=bt709
color_transfer=iec61966-2-1
chroma_location=unspecified
[/FRAME]

Last edited 22 months ago by Balling (previous) (diff)

comment:5 by Balling, 22 months ago

Resolution: needs_more_info
Status: closedreopened

Even after f7bab37c8e66f3c77a5fbb5b5b72c10b0fb4ca5a it still writes Gamma 1.961, that is incorrect. It must be 2.4 gamma. At least it writes PNG cICP now, so mpv should work correctly now, YES!! But AFAIK, fallback for BT.709 must be 2.4 gamma, but I cannot see that in the spec here https://w3c.github.io/PNG-spec/#example-4

Command line

ffmpeg -i C:\Users\ZAQU\Downloads\example.h264 -v:frames 1 mcasa.png

ffmpeg.exe -v verbose -i C:\Users\ZAQU\Downloads\example.h264 -v:frames 1 mcasa.png
ffmpeg version N-109662-g2c3107c3e9-20230125 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (crosstool-NG 1.25.0.90_cf9beb1)
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-shared --disable-static --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-chromaprint --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libkvazaar --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librist --enable-libssh --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --disable-libmfx --enable-libvpl --enable-openal --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20230125
  libavutil      57. 44.100 / 57. 44.100
  libavcodec     59. 57.100 / 59. 57.100
  libavformat    59. 36.100 / 59. 36.100
  libavdevice    59.  8.101 / 59.  8.101
  libavfilter     8. 54.100 /  8. 54.100
  libswscale      6.  8.112 /  6.  8.112
  libswresample   4.  9.100 /  4.  9.100
  libpostproc    56.  7.100 / 56.  7.100


PS C:\Users\XXXX> exiftool.exe  mcasa.png
ExifTool Version Number         : 12.44
File Name                       : mcasa.png
Directory                       : C:/Users/XXXX
File Size                       : 87 kB
File Modification Date/Time     : 2023:01:26 12:59:24+03:00
File Access Date/Time           : 2023:01:26 12:59:42+03:00
File Creation Date/Time         : 2023:01:26 12:59:24+03:00
File Permissions                : -rw-rw-rw-
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 1280
Image Height                    : 720
Bit Depth                       : 8
Color Type                      : RGB
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Pixels Per Unit X               : 1
Pixels Per Unit Y               : 1
Pixel Units                     : Unknown
White Point X                   : 0.3127
White Point Y                   : 0.329
Red X                           : 0.64
Red Y                           : 0.33
Green X                         : 0.3
Green Y                         : 0.6
Blue X                          : 0.15
Blue Y                          : 0.06
Gamma                           : 1.961
Image Size                      : 1280x720
Megapixels                      : 0.922

Sample is here: https://github.com/wang-bin/QtAV/files/1132086/example.zip

Last edited 22 months ago by Balling (previous) (diff)

comment:6 by Balling, 19 months ago

Status: reopenedopen

Hey, I added samples and command line, please fix the gAMA chunk. It is low priority, since all modern apps should just support cICP.

comment:7 by richardssam, 17 months ago

I think I understand where the gamma 1.98 value is coming from. In quicktime and mp4 containers the rec709 ETOF definition is for the "Camera rec709" value, not bt1886.
There is not any explicit setting (particularly in mp4's) which allow you to set bt1886.

Both camera-rec709 (~1.98) and sRGB (~2.2) are approximations, which cannot be correctly represented by a single gamma value, so its somewhat scary for this to be applied automatically.

I dont know what the right answer here is, although we should at least have the ability to override what it uses (particularly if we know the resulting image is bt1886 and does have a proper gamma of 2.4).

comment:8 by Balling, 17 months ago

I think I understand where the gamma 1.98 value is coming from.

It is just BT.709 OETF.

I dont know what the right answer here is,

EOTF for OETF BT.709 is 2.4 gamma only. It is clear as day, it should be 2.4 gamma.

comment:9 by Balling, 6 months ago

From https://github.com/mpv-player/mpv/issues/13438

The PNG specification recommends that PNG writers write gAMA chunks even if it writes other color chunks that override it as fallback metadata to poorly color managed PNG viewers. The actual file is tagged correctly with cICP chunk, which overrides the fallback gAMA chunk.

NO, the PNG SPEC v3 does not specify any such chunk for BT.709. So this is an open issue with a standard. Also, Mac does not use 1.9 gamma for EOTF, it also use close to 2.4.

Note: See TracTickets for help on using tickets.