[FFmpeg-devel] [PATCH] Adds support for constant quality mode in VP9.

James Zern jzern at google.com
Fri Aug 22 04:03:43 CEST 2014


On Thu, Aug 21, 2014 at 4:33 PM, Deb Mukherjee <debargha at google.com> wrote:
> Changes in the parameter mapping for libvpx to support the constant
> quality mode in VP9. The assumption in the patch is that if crf is
> provided but bitrate is 0, then the 'constant quality' mode of VP9
> is used. However if both are present, the 'constrained quality' mode
> is used as before.
> ---
>  libavcodec/libvpxenc.c | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 830a793..a6e5392 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -300,10 +300,17 @@ static av_cold int vpx_init(AVCodecContext *avctx,
>          enccfg.g_pass = VPX_RC_ONE_PASS;
>
>      if (avctx->rc_min_rate == avctx->rc_max_rate &&
> -        avctx->rc_min_rate == avctx->bit_rate && avctx->bit_rate)
> +        avctx->rc_min_rate == avctx->bit_rate && avctx->bit_rate) {
>          enccfg.rc_end_usage = VPX_CBR;
> -    else if (ctx->crf)
> +    } else if (ctx->crf >= 0) {

Is 0 only meaningful for VPX_Q?

>          enccfg.rc_end_usage = VPX_CQ;
> +#if CONFIG_LIBVPX_VP9_ENCODER
> +        if (!avctx->bit_rate && avctx->codec_id == AV_CODEC_ID_VP9)
> +            enccfg.rc_end_usage = VPX_Q;
> +#endif
> +        av_log(avctx, AV_LOG_INFO, "%s usage set with cq=%d\n",
> +               enccfg.rc_end_usage == VPX_CQ ? "VPX_CQ" : "VPX_Q", ctx->crf);

This gets dumped at debug loglevel, probably not necessary here.

> +    }
>
>      if (avctx->bit_rate) {
>          enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000,
> @@ -311,7 +318,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
>      } else {
>          if (enccfg.rc_end_usage == VPX_CQ) {
>              enccfg.rc_target_bitrate = 1000000;
> -        } else {
> +        } else if (enccfg.rc_end_usage != VPX_Q) {
>              avctx->bit_rate = enccfg.rc_target_bitrate * 1000;
>              av_log(avctx, AV_LOG_WARNING,
>                     "Neither bitrate nor constrained quality specified, using default bitrate of %dkbit/sec\n",
> @@ -324,7 +331,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
>      if (avctx->qmax >= 0)
>          enccfg.rc_max_quantizer = avctx->qmax;
>
> -    if (enccfg.rc_end_usage == VPX_CQ) {
> +    if (enccfg.rc_end_usage == VPX_CQ || enccfg.rc_end_usage == VPX_Q) {

When was this introduced? You should be careful with it's use, someone
could be building with an old VP8-only lib.


More information about the ffmpeg-devel mailing list