[FFmpeg-devel] [PATCH] libvpxenc: add color-space option for vp9

James Zern jzern at google.com
Tue Jun 16 07:43:17 CEST 2015


the vp9 bitstream supports 8 values:
unknown (default), bt601, bt709, smpte170, smpte240, bt2020, reserved
and sRGB.
---
 doc/encoders.texi      | 12 ++++++++++++
 libavcodec/libvpxenc.c | 22 ++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 8b0ecb7..09c90c2 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1550,6 +1550,18 @@ Enable frame parallel decodability features.
 @item aq-mode
 Set adaptive quantization mode (0: off (default), 1: variance 2: complexity, 3:
 cyclic refresh).
+ at item color-space
+Set input color space.
+ at table @samp
+ at item unknown
+ at item bt601
+ at item bt709
+ at item smpte170
+ at item smpte240
+ at item bt2020
+ at item reserved
+ at item sRGB
+ at end table
 @end table
 
 @end table
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 28a0e14..10f16e7 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -100,8 +100,12 @@ typedef struct VP8EncoderContext {
     int tile_rows;
     int frame_parallel;
     int aq_mode;
+    int colorspace;
 } VP8Context;
 
+// VP9E_SET_COLOR_SPACE was added just prior to v1.4.0.
+#define HAVE_VP9_COLORSPACE_CONTROL (VPX_ENCODER_ABI_VERSION > 8)
+
 /** String mappings for enum vp8e_enc_control_id */
 static const char *const ctlidstr[] = {
     [VP8E_UPD_ENTROPY]           = "VP8E_UPD_ENTROPY",
@@ -128,6 +132,9 @@ static const char *const ctlidstr[] = {
     [VP9E_SET_TILE_ROWS]               = "VP9E_SET_TILE_ROWS",
     [VP9E_SET_FRAME_PARALLEL_DECODING] = "VP9E_SET_FRAME_PARALLEL_DECODING",
     [VP9E_SET_AQ_MODE]                 = "VP9E_SET_AQ_MODE",
+#if HAVE_VP9_COLORSPACE_CONTROL
+    [VP9E_SET_COLOR_SPACE]             = "VP9E_SET_COLOR_SPACE",
+#endif
 #endif
 };
 
@@ -593,6 +600,10 @@ static av_cold int vpx_init(AVCodecContext *avctx,
             codecctl_int(avctx, VP9E_SET_FRAME_PARALLEL_DECODING, ctx->frame_parallel);
         if (ctx->aq_mode >= 0)
             codecctl_int(avctx, VP9E_SET_AQ_MODE, ctx->aq_mode);
+#if HAVE_VP9_COLORSPACE_CONTROL
+        if (ctx->colorspace >= 0)
+            codecctl_int(avctx, VP9E_SET_COLOR_SPACE, ctx->colorspace);
+#endif
     }
 #endif
 
@@ -968,6 +979,17 @@ static const AVOption vp9_options[] = {
     { "variance",        "Variance based Aq",   0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "aq_mode" },
     { "complexity",      "Complexity based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "aq_mode" },
     { "cyclic",          "Cyclic Refresh Aq",   0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "aq_mode" },
+#if HAVE_VP9_COLORSPACE_CONTROL
+    { "color-space",     "Input color space",                           OFFSET(colorspace),      AV_OPT_TYPE_INT, {.i64 = -1}, -1, 7, VE, "colorspace"},
+    { "unknown",         NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_CS_UNKNOWN},   0, 0, VE, "colorspace" },
+    { "bt601",           NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_CS_BT_601},    0, 0, VE, "colorspace" },
+    { "bt709",           NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_CS_BT_709},    0, 0, VE, "colorspace" },
+    { "smpte170",        NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_CS_SMPTE_170}, 0, 0, VE, "colorspace" },
+    { "smpte240",        NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_CS_SMPTE_240}, 0, 0, VE, "colorspace" },
+    { "bt2020",          NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_CS_BT_2020},   0, 0, VE, "colorspace" },
+    { "reserved",        NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_CS_RESERVED},  0, 0, VE, "colorspace" },
+    { "sRGB",            NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_CS_SRGB},      0, 0, VE, "colorspace" },
+#endif
     LEGACY_OPTIONS
     { NULL }
 };
-- 
2.2.0.rc0.207.ga3a616c



More information about the ffmpeg-devel mailing list