diff options
author | Nicolas Dufresne <nicolas.dufresne@collabora.com> | 2021-05-06 15:04:42 -0400 |
---|---|---|
committer | Nicolas Dufresne <nicolas.dufresne@collabora.com> | 2021-05-06 16:00:47 -0400 |
commit | d9a0313aa0a6d71ab7fc9ac6495cfdb3f37a2468 (patch) | |
tree | d7ceb8f9507718bbe5ebb97e2cb1a13a01a71dfd /ext/vpx | |
parent | 91da1c3c08883a4b873b0a8704181ba1a3d0b113 (diff) | |
download | gstreamer-plugins-good-d9a0313aa0a6d71ab7fc9ac6495cfdb3f37a2468.tar.gz |
vp9enc: Add color range support
When setting the colorspace, we now clear the range to reduced range,
the default, and then we also set the range so the VP9 encoder encodes
the right information in the bitstream.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/975>
Diffstat (limited to 'ext/vpx')
-rw-r--r-- | ext/vpx/gstvp9enc.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/ext/vpx/gstvp9enc.c b/ext/vpx/gstvp9enc.c index fca6e1168..c938e1608 100644 --- a/ext/vpx/gstvp9enc.c +++ b/ext/vpx/gstvp9enc.c @@ -312,10 +312,11 @@ gst_vp9_enc_get_property (GObject * object, guint prop_id, GValue * value, } static vpx_color_space_t -gst_vp9_get_vpx_colorspace (GstVPXEnc * encoder, GstVideoColorimetry * cinfo, +gst_vp9_get_vpx_colorspace (GstVPXEnc * encoder, GstVideoColorimetry * in_cinfo, GstVideoFormat format) { vpx_color_space_t colorspace = VPX_CS_UNKNOWN; + GstVideoColorimetry cinfo = *in_cinfo; gchar *colorimetry_str; guint i; @@ -331,7 +332,9 @@ gst_vp9_get_vpx_colorspace (GstVPXEnc * encoder, GstVideoColorimetry * cinfo, GST_VIDEO_COLORIMETRY_BT2020, VPX_CS_BT_2020} }; - colorimetry_str = gst_video_colorimetry_to_string (cinfo); + /* We support any range, all mapped CSC are by default reduced range. */ + cinfo.range = GST_VIDEO_COLOR_RANGE_16_235; + colorimetry_str = gst_video_colorimetry_to_string (&cinfo); if (colorimetry_str != NULL) { for (i = 0; i < G_N_ELEMENTS (colorimetry_map); ++i) { @@ -365,6 +368,17 @@ gst_vp9_get_vpx_colorspace (GstVPXEnc * encoder, GstVideoColorimetry * cinfo, return colorspace; } +static gint +gst_vp9_get_vpx_color_range (GstVideoColorimetry * colorimetry) +{ + if (colorimetry->range == GST_VIDEO_COLOR_RANGE_0_255) + /* Full range (0..255 or HBD equivalent) */ + return 1; + + /* Limited range (16..235 or HBD equivalent) */ + return 0; +} + static gboolean gst_vp9_enc_configure_encoder (GstVPXEnc * encoder, GstVideoCodecState * state) { @@ -380,6 +394,13 @@ gst_vp9_enc_configure_encoder (GstVPXEnc * encoder, GstVideoCodecState * state) "Failed to set VP9E_SET_COLOR_SPACE: %s", gst_vpx_error_name (status)); } + status = vpx_codec_control (&encoder->encoder, VP9E_SET_COLOR_RANGE, + gst_vp9_get_vpx_color_range (&GST_VIDEO_INFO_COLORIMETRY (info))); + if (status != VPX_CODEC_OK) { + GST_WARNING_OBJECT (encoder, + "Failed to set VP9E_SET_COLOR_RANGE: %s", gst_vpx_error_name (status)); + } + status = vpx_codec_control (&encoder->encoder, VP9E_SET_TILE_COLUMNS, vp9enc->tile_columns); |