Quoting Mark Thompson (2016-11-30 00:01:21)
> ---
> I was avoiding this one until I could do VP9 at the same time because the 
> headers and probability stuff looked nasty.  Turns out that was entirely 
> unfounded, because the i965 driver doesn't actually support any of those 
> things, and therefore it's pretty much trivial if we only support P frames.  
> (That does also mean that the result is atrocious, so this is mainly a 
> curiosity for now.)
> 
> 
>  configure                     |   3 +
>  libavcodec/Makefile           |   1 +
>  libavcodec/allcodecs.c        |   1 +
>  libavcodec/vaapi_encode_vp8.c | 261 
> ++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 266 insertions(+)
>  create mode 100644 libavcodec/vaapi_encode_vp8.c
> 
> +
> +static int vaapi_encode_vp8_write_quant_table(AVCodecContext *avctx,
> +                                              VAAPIEncodePicture *pic,
> +                                              int index, int *type,
> +                                              char *data, size_t *data_len)
> +{
> +    VAAPIEncodeContext     *ctx = avctx->priv_data;
> +    VAAPIEncodeVP8Context *priv = ctx->priv_data;
> +    VAQMatrixBufferVP8 quant;
> +    int i, q;
> +
> +    if (index > 0)
> +        return AVERROR_EOF;
> +
> +    if (*data_len < sizeof(quant))
> +        return AVERROR(EINVAL);
> +    *type = VAQMatrixBufferType;
> +
> +    if (pic->type == PICTURE_TYPE_IDR)
> +        q = priv->qindex_idr;
> +    else
> +        q = priv->qindex_p;
> +
> +    for (i = 0; i < 4; i++)
> +        quant.quantization_index[i] = q;
> +    for (i = 0; i < 5; i++)
> +        quant.quantization_index_delta[i] = 0;
> +
> +    memcpy(data, &quant, *data_len = sizeof(quant));

This is sneaky and all kinds of evil. Just put *data_len = sizeof(quant)
right after the check above.

> +    return 0;
> +}
> +
> +static av_cold int vaapi_encode_vp8_configure(AVCodecContext *avctx)
> +{
> +    VAAPIEncodeContext     *ctx = avctx->priv_data;
> +    VAAPIEncodeVP8Context *priv = ctx->priv_data;
> +    VAAPIEncodeVP8Options  *opt = ctx->codec_options;
> +
> +    priv->qindex_p = opt->qindex;
> +    if (avctx->i_quant_factor > 0.0)
> +        priv->qindex_idr = (int)((priv->qindex_p * avctx->i_quant_factor +
> +                                 avctx->i_quant_offset) + 0.5);
> +    else
> +        priv->qindex_idr = priv->qindex_p;
> +
> +    return 0;
> +}
> +
> +static const VAAPIEncodeType vaapi_encode_type_vp8 = {
> +    .configure             = &vaapi_encode_vp8_configure,
> +
> +    .priv_data_size        = sizeof(VAAPIEncodeVP8Context),
> +
> +    .sequence_params_size  = sizeof(VAEncSequenceParameterBufferVP8),
> +    .init_sequence_params  = &vaapi_encode_vp8_init_sequence_params,
> +
> +    .picture_params_size   = sizeof(VAEncPictureParameterBufferVP8),
> +    .init_picture_params   = &vaapi_encode_vp8_init_picture_params,
> +
> +    .write_extra_buffer    = &vaapi_encode_vp8_write_quant_table,
> +};
> +
> +static av_cold int vaapi_encode_vp8_init(AVCodecContext *avctx)
> +{
> +    VAAPIEncodeContext *ctx = avctx->priv_data;
> +
> +    if (avctx->max_b_frames > 0) {
> +        av_log(avctx, AV_LOG_ERROR, "B-frames are not supported.\n");
> +        return AVERROR_PATCHWELCOME;
> +    }
> +
> +    ctx->codec = &vaapi_encode_type_vp8;
> +
> +    ctx->va_profile    = VAProfileVP8Version0_3;
> +    ctx->va_entrypoint = VAEntrypointEncSlice;
> +    ctx->va_rt_format  = VA_RT_FORMAT_YUV420;
> +
> +    if (avctx->bit_rate > 0)
> +        ctx->va_rc_mode = VA_RC_CBR;
> +    else
> +        ctx->va_rc_mode = VA_RC_CQP;
> +
> +    // Packed headers are not currently supported.
> +    ctx->va_packed_headers = 0;
> +
> +    ctx->surface_width  = FFALIGN(avctx->width,  16);
> +    ctx->surface_height = FFALIGN(avctx->height, 16);
> +
> +    return ff_vaapi_encode_init(avctx);
> +}
> +
> +#define OFFSET(x) (offsetof(VAAPIEncodeContext, codec_options_data) + \
> +                   offsetof(VAAPIEncodeVP8Options, x))
> +#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
> +static const AVOption vaapi_encode_vp8_options[] = {
> +    { "qindex", "Constant Q-index (for non-key frames; scaled by 
> qfactor/qoffset for key frames)",
> +      OFFSET(qindex), AV_OPT_TYPE_INT, { .i64 = 40 }, 0, 127, FLAGS },

Is this analogous to the quantizer scale in mpeg2 and friends? Perhaps
you should use the global_quality option then and not add yet more
private options.

-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to