#3785: SWSCALE: in_range, in_color_matrix, out_range, out_color_matrix incorrect -------------------------------------+------------------------------------- Reporter: troy_s | Type: defect Status: new | Priority: normal Component: | Version: git- undetermined | master Keywords: | Blocked By: colormanagement colorspace 709 | Reproduced by developer: 0 601 | Blocking: | Analyzed by developer: 0 | -------------------------------------+------------------------------------- '''Summary of the bug''': Seems that swscale is still sadly mangling RGB to YCbCr and vice versa transforms. Disabled all ASM speedups to avoid code path issues, as were previously hard coded to 601 coefficents etc. '''How to reproduce''': Encode a test chart and check values. Test chart available from http://www .belle-nuit.com/test-chart. '''Expected versus Results''': BT.709 and sRGB share identical luminance coefficients. An sRGB image, encoded at full range using BT.709 primaries should decode to a perfect 1:1 regarding RGB values, compression notwithstanding. Sampling the upper row of colors using the provided test chart, we can see some issues with the encoding / decoding step, when using FFPLAY with the corresponding scale commands. For example, an encode using {{{ ./ffmpeg -loop 1 -i ~/Downloads/testchart.tif -t 3 -c:v h264 -vf "scale=in_range=full:in_color_matrix=bt709:out_range=full:out_color_matrix=bt709" out709-full.mp4 }}} Should produce a perfect 1:1 when played back with {{{ ./ffplay -vf "scale=in_range=full:in_color_matrix=bt709:out_range=full:out_color_matrix=bt709" out709-full.mp4 }}} When we sample the sRGB / 709 values using an image editor, the top row should result in RGB values as follows: {{{ Name R G B Yellow: 180 180 16 Cyan: 16 180 180 Magenta: 180 16 180 Green: 16 180 16 Red: 180 16 16 Blue: 16 16 180 }}} Given that 709 and sRGB share identical primaries, and broadcast scaling is set to full range, there should be a perfect 1:1 result with the values. However, what we find with playback via the ffmpeg command set with proper values is: {{{ Name R G B Yellow: 179 190 22 Cyan: 31 197 180 Magenta: 167 0 176 Green: 30 209 21 Red: 166 0 19 Blue: 17 5 173 }}} There appears to be breakage with regard to the application of the coefficients, as well as possibly misinterpretation of the full range settings. The are some transforms that yield vaguely close values. However, these suffer from quantization issues where no such should occur. It would seem that all transformations are likely being performed at the relative bit depth for performance. Sadly, this corrupts the values quite significantly. {{{ ./ffmpeg -loop 1 -i ~/Downloads/testchart.tif -t 3 -c:v h264 -vf "scale=in_range=full:in_color_matrix=bt601:out_range=full:out_color_matrix=bt601" out601-full.mp4 }}} The following, despite being 601 coefficients, should yield perfect 1:1 with RGB values (RGB being a relative color space) but quantization issues again result. {{{ ./ffplay -vf "scale=in_range=full:in_color_matrix=bt601:out_range=full:out_color_matrix=bt601" out601-full.mp4 }}} Further testing of the in_range and out_range specifics will be conducted when the basic color coefficients issue is corrected. '''Conclusion''': Some mangling is still present in the color handling in FFMPEG. Quantization issues can likely be expected until a float (likely non- realtime) option is introduced for higher quality frame by frame encoding / decoding. However, even with quantization issues, the encoding / decoding coefficients are not responding / respected in correct fashion for 709 to 709 (1:1 with sRGB content). -- Ticket URL: <https://trac.ffmpeg.org/ticket/3785> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker