Skip to content

video-info: encoded format can have RGB color-matrix

Célestin Marot requested to merge marotc/gstreamer:validate_colorimetry into main

In some elements, like here in the videodecoder base class, a GstVideoInfo structure is created from the caps of an encoded frame thanks to gst_video_info_from_caps(). If the caps contains information about the colorimetry of the encoded frame and it specifies an RGB (identity) color matrix, gst_video_info_from_caps() issues some warnings:

# Here I use pngdec to demonstrate the problem but it could be any video decoder 
gst-launch-1.0 --gst-debug=3 videotestsrc ! "video/x-raw, colorimetry=sRGB" ! pngenc ! pngdec ! fakesink
# here are the warnings, present using latest commit e8c923ebde
WARN              video-info video-info.c:196:validate_colorimetry: color matrix RGB is only supported with RGB format, ENCODED is not
WARN              video-info video-info.c:520:gst_video_info_from_caps: invalid colorimetry, using default
WARN              video-info video-info.c:743:gst_video_info_to_caps: invalid matrix 0 for RGB format, using RGB

and all the colorimetry information is lost for the gstvideoencoder subclass... (well, it is still in the caps, but anyone would expect it to also be in the video-info structure).

I am pretty sure that gst_video_info_from_caps() should keep the colorimetry information of the encoded frame as it can be very useful to retrieve the full caps of the original image once it is decoded.

Encoded frames format is set to GST_VIDEO_FORMAT_ENCODED, which has the colorspace flag GST_VIDEO_FORMAT_FLAG_COMPLEX, but not the RGB or YUV flag, which is why validate_colorimetry() fails with the above warning. I think we can say that a "Complex" format can possibly have an associated RGB color-matrix, which is exactly what this very small commit fixes. (EDIT following this comment)

Edited by Célestin Marot

Merge request reports