[FFmpeg-devel] [PATCH] QSV : Added look ahead rate control mode

Michael Niedermayer michael at niedermayer.cc
Fri Aug 21 00:24:25 CEST 2015


On Thu, Aug 20, 2015 at 02:34:22PM +0100, Sven Dueking wrote:
> From: Sven Dueking <sven at nablet.com>
> 
> ---
>  libavcodec/qsvenc.c      | 36 +++++++++++++++++++++++++++++++++---
>  libavcodec/qsvenc.h      | 12 ++++++++++++
>  libavcodec/qsvenc_h264.c | 12 ++++++++++++
>  3 files changed, 57 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 1532258..935abdd 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -106,10 +106,21 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
>      } else if (avctx->rc_max_rate == avctx->bit_rate) {
>          q->param.mfx.RateControlMethod = MFX_RATECONTROL_CBR;
>          ratecontrol_desc = "constant bitrate (CBR)";

> -    } else if (!avctx->rc_max_rate) {
> +    }
> +    else if (!avctx->rc_max_rate) {

unrelated and unneeded change, the style is also inconsistent with
the rest of the file


> +#if QSV_VERSION_ATLEAST(1,7)
> +        if (q->look_ahead) {
> +            q->param.mfx.RateControlMethod = MFX_RATECONTROL_LA;
> +            ratecontrol_desc = "lookahead (LA)";
> +        } else {
> +#endif
>          q->param.mfx.RateControlMethod = MFX_RATECONTROL_AVBR;
>          ratecontrol_desc = "average variable bitrate (AVBR)";
> +#if QSV_VERSION_ATLEAST(1,7)
> +        }
> +#endif

you can avoid one #if:

+#if QSV_VERSION_ATLEAST(1,7)
+        if (q->look_ahead) {
+            q->param.mfx.RateControlMethod = MFX_RATECONTROL_LA;
+            ratecontrol_desc = "lookahead (LA)";
+        } else
+#endif
         {
            q->param.mfx.RateControlMethod = MFX_RATECONTROL_AVBR;
            ratecontrol_desc = "average variable bitrate (AVBR)";
         }



> -    } else {
> +    }
> +    else {

unrelated and unneeded change

please read your patch before submiting and makre sure its clean
and there are no obvious and easy ways to simplify that havnt been
done.


>          q->param.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
>          ratecontrol_desc = "variable bitrate (VBR)";
>      }
> @@ -132,6 +143,9 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
>  
>          break;
>      case MFX_RATECONTROL_AVBR:
> +#if QSV_VERSION_ATLEAST(1,7)
> +    case MFX_RATECONTROL_LA:
> +#endif
>          q->param.mfx.TargetKbps  = avctx->bit_rate / 1000;
>          q->param.mfx.Convergence = q->avbr_convergence;
>          q->param.mfx.Accuracy    = q->avbr_accuracy;
> @@ -151,7 +165,23 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
>  
>          q->extparam[0] = (mfxExtBuffer *)&q->extco;
>  
> -        q->param.ExtParam    = q->extparam;
> +#if QSV_VERSION_ATLEAST(1,6)
> +        q->extco2.Header.BufferId      = MFX_EXTBUFF_CODING_OPTION2;
> +        q->extco2.Header.BufferSz      = sizeof(q->extco2);
> +
> +#if QSV_VERSION_ATLEAST(1,7)
> +        // valid value range is from 10 to 100 inclusive
> +        // to instruct the encoder to use the default value this should be set to zero
> +        q->extco2.LookAheadDepth        = q->look_ahead_depth != 0 ? FFMAX(10, q->look_ahead_depth) : 0;
> +#endif
> +#if QSV_VERSION_ATLEAST(1,8)
> +        q->extco2.LookAheadDS           = q->look_ahead_downsampling;
> +#endif
> +
> +        q->extparam[1] = (mfxExtBuffer *)&q->extco2;
> +
> +#endif

> +	    q->param.ExtParam    = q->extparam;

tabs are forbidden in *.c/h files


>          q->param.NumExtParam = FF_ARRAY_ELEMS(q->extparam);
>      }
>  
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index 2316488..c096a54 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -50,7 +50,12 @@ typedef struct QSVEncContext {
>      mfxFrameAllocRequest req;
>  
>      mfxExtCodingOption  extco;
> +#if QSV_VERSION_ATLEAST(1,6)
> +    mfxExtCodingOption2 extco2;
> +    mfxExtBuffer *extparam[2];
> +#else
>      mfxExtBuffer *extparam[1];
> +#endif
>  
>      AVFifoBuffer *async_fifo;
>  
> @@ -62,6 +67,13 @@ typedef struct QSVEncContext {
>      int avbr_accuracy;
>      int avbr_convergence;
>      int pic_timing_sei;

> +#if QSV_VERSION_ATLEAST(1,7)
> +    int look_ahead;
> +    int look_ahead_depth;
> +#endif
> +#if QSV_VERSION_ATLEAST(1,8)
> +    int look_ahead_downsampling;
> +#endif

these do not need to be conditional


>  
>      char *load_plugins;
>  } QSVEncContext;
> diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
> index b15f6b2..bd401e1 100644
> --- a/libavcodec/qsvenc_h264.c
> +++ b/libavcodec/qsvenc_h264.c
> @@ -71,6 +71,18 @@ static const AVOption options[] = {
>      { "avbr_convergence", "Convergence of the AVBR ratecontrol", OFFSET(qsv.avbr_convergence), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
>      { "pic_timing_sei",    "Insert picture timing SEI with pic_struct_syntax element", OFFSET(qsv.pic_timing_sei), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
>  
> +#if QSV_VERSION_ATLEAST(1,7)
> +    { "look_ahead",       "Use VBR algorithm with look ahead",    OFFSET(qsv.look_ahead),       AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
> +    { "look_ahead_depth", "Depth of look ahead in number frames", OFFSET(qsv.look_ahead_depth), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, VE },
> +#endif
> +

> +#if QSV_VERSION_ATLEAST(1,8)
> +    { "look_ahead_downsampling", NULL, OFFSET(qsv.look_ahead_downsampling), AV_OPT_TYPE_INT, { .i64 = MFX_LOOKAHEAD_DS_UNKNOWN }, 0, INT_MAX, VE, "look_ahead_downsampling" },

INT_MAX is likely wrong here


> +    { "unknown"                , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_LOOKAHEAD_DS_UNKNOWN }, INT_MIN, INT_MAX,     VE, "look_ahead_downsampling" },
> +    { "off"                    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_LOOKAHEAD_DS_OFF     }, INT_MIN, INT_MAX,     VE, "look_ahead_downsampling" },
> +    { "2x"                     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_LOOKAHEAD_DS_2x      }, INT_MIN, INT_MAX,     VE, "look_ahead_downsampling" },
> +#endif

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150821/c2c26c63/attachment.sig>


More information about the ffmpeg-devel mailing list