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

Michael Niedermayer michael at niedermayer.cc
Thu Aug 27 17:47:43 CEST 2015


On Thu, Aug 27, 2015 at 11:02:44AM +0200, Sven Dueking wrote:
> > -----Ursprüngliche Nachricht-----
> > Von: ffmpeg-devel [mailto:ffmpeg-devel-bounces at ffmpeg.org] Im Auftrag
> > von Sven Dueking
> > Gesendet: Freitag, 21. August 2015 10:18
> > An: ffmpeg-devel at ffmpeg.org
> > Cc: Sven Dueking
> > Betreff: [FFmpeg-devel] [PATCH] QSV : Added look ahead rate control
> > mode
> > 
> > From: Sven Dueking <sven at nablet.com>
> > 
> > ---
> >  libavcodec/qsvenc.c      | 31 +++++++++++++++++++++++++++++--
> >  libavcodec/qsvenc.h      |  8 ++++++++
> >  libavcodec/qsvenc_h264.c | 12 ++++++++++++
> >  3 files changed, 49 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index
> > 1532258..1aeab03 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -107,8 +107,16 @@ static int init_video_param(AVCodecContext *avctx,
> > QSVEncContext *q)
> >          q->param.mfx.RateControlMethod = MFX_RATECONTROL_CBR;
> >          ratecontrol_desc = "constant bitrate (CBR)";
> >      } else if (!avctx->rc_max_rate) {
> > -        q->param.mfx.RateControlMethod = MFX_RATECONTROL_AVBR;
> > -        ratecontrol_desc = "average variable bitrate (AVBR)";
> > +#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 {
> >          q->param.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
> >          ratecontrol_desc = "variable bitrate (VBR)"; @@ -132,6 +140,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,6 +162,22 @@ static int init_video_param(AVCodecContext *avctx,
> > QSVEncContext *q)
> > 
> >          q->extparam[0] = (mfxExtBuffer *)&q->extco;
> > 
> > +#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;
> >          q->param.NumExtParam = FF_ARRAY_ELEMS(q->extparam);
> >      }
> > diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h index
> > 2316488..2a21f82 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,9 @@ typedef struct QSVEncContext {
> >      int avbr_accuracy;
> >      int avbr_convergence;
> >      int pic_timing_sei;
> > +    int look_ahead;
> > +    int look_ahead_depth;
> > +    int look_ahead_downsampling;
> > 
> >      char *load_plugins;
> >  } QSVEncContext;
> > diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c index
> > b15f6b2..b569efe 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 }, MFX_LOOKAHEAD_DS_UNKNOWN,
> > MFX_LOOKAHEAD_DS_2x, VE, "look_ahead_downsampling" },
> > +    { "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
> > +
> >      { "profile", NULL, OFFSET(qsv.profile), AV_OPT_TYPE_INT, { .i64 =
> > MFX_PROFILE_UNKNOWN }, 0, INT_MAX, VE, "profile" },
> >      { "unknown" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> > MFX_PROFILE_UNKNOWN      }, INT_MIN, INT_MAX,     VE, "profile" },
> >      { "baseline", NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> > MFX_PROFILE_AVC_BASELINE }, INT_MIN, INT_MAX,     VE, "profile" },
> > --
> > 1.8.3.1
> 
> Hi Michael,
> 
> sorry to bother you, is this patch still not ok ?

Iam not QSV maintainer, indeed i still dont have a setup to test QSV,
the QSV maintainer should review this patch, or is he still on
vacation ?

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf
-------------- 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/20150827/c2fb2572/attachment.sig>


More information about the ffmpeg-devel mailing list