[FFmpeg-devel] [PATCH] libvpx: Support setting color range for vp9.

Sasi Inguva isasi at google.com
Wed Dec 30 19:23:24 CET 2015


Pass through color range to vp9 encoder, and parse it in libvpxdec

Signed-off-by: Sasi Inguva <isasi at google.com>
---
 libavcodec/libvpxdec.c |  4 ++++
 libavcodec/libvpxenc.c | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c
index 7267590..169a137 100644
--- a/libavcodec/libvpxdec.c
+++ b/libavcodec/libvpxdec.c
@@ -68,6 +68,10 @@ static int set_pix_fmt(AVCodecContext *avctx, struct vpx_image *img)
         AVCOL_SPC_SMPTE240M, AVCOL_SPC_BT2020_NCL, AVCOL_SPC_RESERVED, AVCOL_SPC_RGB,
     };
     avctx->colorspace = colorspaces[img->cs];
+    static const enum AVColorRange color_ranges[8] = {
+        AVCOL_RANGE_MPEG, AVCOL_RANGE_JPEG
+    };
+    avctx->color_range = color_ranges[img->range];
 #endif
     if (avctx->codec_id == AV_CODEC_ID_VP8 && img->fmt != VPX_IMG_FMT_I420)
         return AVERROR_INVALIDDATA;
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 8588241..8baff8f 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -123,6 +123,7 @@ static const char *const ctlidstr[] = {
     [VP9E_SET_AQ_MODE]                 = "VP9E_SET_AQ_MODE",
 #if VPX_ENCODER_ABI_VERSION > 8
     [VP9E_SET_COLOR_SPACE]             = "VP9E_SET_COLOR_SPACE",
+    [VP9E_SET_COLOR_RANGE]             = "VP9E_SET_COLOR_RANGE",
 #endif
 #endif
 };
@@ -366,6 +367,24 @@ static void set_colorspace(AVCodecContext *avctx)
     }
     codecctl_int(avctx, VP9E_SET_COLOR_SPACE, vpx_cs);
 }
+
+static void set_color_range(AVCodecContext *avctx)
+{
+    enum vpx_color_range vpx_cr;
+    switch (avctx->color_range) {
+    case AVCOL_RANGE_UNSPECIFIED:
+    case AVCOL_RANGE_MPEG:
+        vpx_cr = VPX_CR_STUDIO_RANGE; break;
+    case AVCOL_RANGE_JPEG:
+        vpx_cr = VPX_CR_FULL_RANGE; break;
+    default:
+        av_log(avctx, AV_LOG_WARNING, "Unsupported color range (%d)\n",
+               avctx->color_range);
+        return;
+    }
+
+    codecctl_int(avctx, VP9E_SET_COLOR_RANGE, vpx_cr);
+}
 #endif
 #endif
 
@@ -615,6 +634,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
             codecctl_int(avctx, VP9E_SET_AQ_MODE, ctx->aq_mode);
 #if VPX_ENCODER_ABI_VERSION > 8
         set_colorspace(avctx);
+        set_color_range(avctx);
 #endif
     }
 #endif
-- 
2.6.0.rc2.230.g3dd15c0



More information about the ffmpeg-devel mailing list