Commit 9b747500 authored by James Zern's avatar James Zern

libvpxenc: support setting colorspace for vp9

the vp9 bitstream supports 8 values:
unknown (default), bt601, bt709, smpte170, smpte240, bt2020, reserved
and sRGB.
Reviewed-by: 's avatarRonald S. Bultje <rsbultje@gmail.com>
Signed-off-by: 's avatarJames Zern <jzern@google.com>
parent 631d56ff
...@@ -1550,6 +1550,18 @@ Enable frame parallel decodability features. ...@@ -1550,6 +1550,18 @@ Enable frame parallel decodability features.
@item aq-mode @item aq-mode
Set adaptive quantization mode (0: off (default), 1: variance 2: complexity, 3: Set adaptive quantization mode (0: off (default), 1: variance 2: complexity, 3:
cyclic refresh). cyclic refresh).
@item colorspace @emph{color-space}
Set input color space. The VP9 bitstream supports signaling the following
colorspaces:
@table @option
@item @samp{rgb} @emph{sRGB}
@item @samp{bt709} @emph{bt709}
@item @samp{unspecified} @emph{unknown}
@item @samp{bt470bg} @emph{bt601}
@item @samp{smpte170m} @emph{smpte170}
@item @samp{smpte240m} @emph{smpte240}
@item @samp{bt2020_ncl} @emph{bt2020}
@end table
@end table @end table
@end table @end table
......
...@@ -128,6 +128,9 @@ static const char *const ctlidstr[] = { ...@@ -128,6 +128,9 @@ static const char *const ctlidstr[] = {
[VP9E_SET_TILE_ROWS] = "VP9E_SET_TILE_ROWS", [VP9E_SET_TILE_ROWS] = "VP9E_SET_TILE_ROWS",
[VP9E_SET_FRAME_PARALLEL_DECODING] = "VP9E_SET_FRAME_PARALLEL_DECODING", [VP9E_SET_FRAME_PARALLEL_DECODING] = "VP9E_SET_FRAME_PARALLEL_DECODING",
[VP9E_SET_AQ_MODE] = "VP9E_SET_AQ_MODE", [VP9E_SET_AQ_MODE] = "VP9E_SET_AQ_MODE",
#if VPX_ENCODER_ABI_VERSION > 8
[VP9E_SET_COLOR_SPACE] = "VP9E_SET_COLOR_SPACE",
#endif
#endif #endif
}; };
...@@ -349,6 +352,29 @@ static int set_pix_fmt(AVCodecContext *avctx, vpx_codec_caps_t codec_caps, ...@@ -349,6 +352,29 @@ static int set_pix_fmt(AVCodecContext *avctx, vpx_codec_caps_t codec_caps,
av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n"); av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
#if VPX_ENCODER_ABI_VERSION > 8
static void set_colorspace(AVCodecContext *avctx)
{
enum vpx_color_space vpx_cs;
switch (avctx->colorspace) {
case AVCOL_SPC_RGB: vpx_cs = VPX_CS_SRGB; break;
case AVCOL_SPC_BT709: vpx_cs = VPX_CS_BT_709; break;
case AVCOL_SPC_UNSPECIFIED: vpx_cs = VPX_CS_UNKNOWN; break;
case AVCOL_SPC_RESERVED: vpx_cs = VPX_CS_RESERVED; break;
case AVCOL_SPC_BT470BG: vpx_cs = VPX_CS_BT_601; break;
case AVCOL_SPC_SMPTE170M: vpx_cs = VPX_CS_SMPTE_170; break;
case AVCOL_SPC_SMPTE240M: vpx_cs = VPX_CS_SMPTE_240; break;
case AVCOL_SPC_BT2020_NCL: vpx_cs = VPX_CS_BT_2020; break;
default:
av_log(avctx, AV_LOG_WARNING, "Unsupported colorspace (%d)\n",
avctx->colorspace);
return;
}
codecctl_int(avctx, VP9E_SET_COLOR_SPACE, vpx_cs);
}
#endif
#endif #endif
static av_cold int vpx_init(AVCodecContext *avctx, static av_cold int vpx_init(AVCodecContext *avctx,
...@@ -593,6 +619,9 @@ static av_cold int vpx_init(AVCodecContext *avctx, ...@@ -593,6 +619,9 @@ static av_cold int vpx_init(AVCodecContext *avctx,
codecctl_int(avctx, VP9E_SET_FRAME_PARALLEL_DECODING, ctx->frame_parallel); codecctl_int(avctx, VP9E_SET_FRAME_PARALLEL_DECODING, ctx->frame_parallel);
if (ctx->aq_mode >= 0) if (ctx->aq_mode >= 0)
codecctl_int(avctx, VP9E_SET_AQ_MODE, ctx->aq_mode); codecctl_int(avctx, VP9E_SET_AQ_MODE, ctx->aq_mode);
#if VPX_ENCODER_ABI_VERSION > 8
set_colorspace(avctx);
#endif
} }
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment