[FFmpeg-devel] [PATCH] libvpxenc: support setting colorspace for vp9

James Zern jzern at google.com
Sun Jun 21 01:33:11 CEST 2015


On Sat, Jun 20, 2015 at 12:29 PM, Ronald S. Bultje <rsbultje at gmail.com> wrote:
> Hi,
>
> On Sat, Jun 20, 2015 at 3:15 PM, James Zern <jzern at google.com> wrote:
>
>> On Wed, Jun 17, 2015 at 12:20 PM, James Zern <jzern at google.com> wrote:
>> > the vp9 bitstream supports 8 values:
>> > unknown (default), bt601, bt709, smpte170, smpte240, bt2020, reserved
>> > and sRGB.
>> > ---
>> >  doc/encoders.texi      | 12 ++++++++++++
>> >  libavcodec/libvpxenc.c | 29 +++++++++++++++++++++++++++++
>> >  2 files changed, 41 insertions(+)
>> >
>>
>> I'll submit this soon if there are no more comments.
>>
>> > diff --git a/doc/encoders.texi b/doc/encoders.texi
>> > index 8b0ecb7..8fed2fc 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 colorspace @emph{color-space}
>> > +Set input color space. The VP9 bitstream supports signaling the
>> following
>> > +colorspaces:
>> > + at table @option
>> > + at item @samp{rgb} @emph{sRGB}
>> > + at item @samp{bt709} @emph{bt709}
>> > + at item @samp{unspecified} @emph{unknown}
>> > + at item @samp{bt470bg} @emph{bt601}
>> > + at item @samp{smpte170m} @emph{smpte170}
>> > + at item @samp{smpte240m} @emph{smpte240}
>> > + at item @samp{bt2020_ncl} @emph{bt2020}
>> > + at end table
>> >  @end table
>> >
>> >  @end table
>> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
>> > index 28a0e14..b2deb5d 100644
>> > --- a/libavcodec/libvpxenc.c
>> > +++ b/libavcodec/libvpxenc.c
>> > @@ -128,6 +128,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 VPX_ENCODER_ABI_VERSION > 8
>> > +    [VP9E_SET_COLOR_SPACE]             = "VP9E_SET_COLOR_SPACE",
>> > +#endif
>> >  #endif
>> >  };
>> >
>> > @@ -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");
>> >      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
>> >
>> >  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);
>> >          if (ctx->aq_mode >= 0)
>> >              codecctl_int(avctx, VP9E_SET_AQ_MODE, ctx->aq_mode);
>> > +#if VPX_ENCODER_ABI_VERSION > 8
>> > +        set_colorspace(avctx);
>> > +#endif
>> >      }
>> >  #endif
>> >
>> > --
>> > 2.2.0.rc0.207.ga3a616c
>>
>
> Yes I think this is fine.
>

applied.


More information about the ffmpeg-devel mailing list