[PATCH] gstreamer: Handle GST_VIDEO_TRANSFER_BT601

Hou Qi qi.hou at nxp.com
Fri Nov 8 10:12:03 CET 2024


The conversions back and forth between GStreamer colorimetry and
libcamera color space are not invariant for the bt601 colorimetry.
The reason is that Rec709 transfer function defined in GStreamer
as GST_VIDEO_TRANSFER_BT709 (5), is to be replaced by its alias
GST_VIDEO_TRANSFER_BT601 (16) only for the case of bt601 (aka 2:4:16:4)
colorimetry - see [1].

Currently the composition of the GStreamer/libcamera conversions:
colorimetry_from_colorspace (colorspace_from_colorimetry (bt601))
returns 2:4:5:4 instead of the expected 2:4:16:4 (bt601). This
causes negotiation error when the downstream element explicitly
expects bt601 colorimetry.

Minimal example to reproduce the issue is with a pipeline handler
that do not set the optional color space in the stream configuration,
for instance vimc or imx8-isi:
export LIBCAMERA_PIPELINES_MATCH_LIST="vimc,imx8-isi"
gst-launch-1.0 -v libcamerasrc ! video/x-raw,colorimetry=bt601 ! fakesink

Above pipeline fails to start. This change updates colorimetry_from_colorspace()
to use the expected GST_VIDEO_TRANSFER_BT601 (16) alternative
definition for the Rec709 transfer function, in order to fix the
conversion from libcamera color space towards the bt601 colorimetry.
This bt601 colorimetry special case is identified by the usage of
the Rec709 transfer function combined with the primaries
GST_VIDEO_COLOR_PRIMARIES_SMPTE170M (4).

[1] https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/724

Signed-off-by: Hou Qi <qi.hou at nxp.com>
---
 src/gstreamer/gstlibcamera-utils.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
index 732987ef..b2d64733 100644
--- a/src/gstreamer/gstlibcamera-utils.cpp
+++ b/src/gstreamer/gstlibcamera-utils.cpp
@@ -112,7 +112,14 @@ colorimetry_from_colorspace(const ColorSpace &colorSpace)
 		colorimetry.transfer = GST_VIDEO_TRANSFER_SRGB;
 		break;
 	case ColorSpace::TransferFunction::Rec709:
+#if GST_CHECK_VERSION(1, 18, 0)
+		if (colorSpace.primaries == ColorSpace::Primaries::Smpte170m)
+			colorimetry.transfer = GST_VIDEO_TRANSFER_BT601;
+		else
+			colorimetry.transfer = GST_VIDEO_TRANSFER_BT709;
+#else
 		colorimetry.transfer = GST_VIDEO_TRANSFER_BT709;
+#endif
 		break;
 	}
 
-- 
2.34.1



More information about the libcamera-devel mailing list