mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-27 09:52:17 +00:00
avcodec/qsv : Added look ahead rate control mode
Reviewed-by: Ivan Uskov <ivan.uskov@nablet.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
dead1964ea
commit
67e87f8050
@ -107,8 +107,16 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
|
|||||||
q->param.mfx.RateControlMethod = MFX_RATECONTROL_CBR;
|
q->param.mfx.RateControlMethod = MFX_RATECONTROL_CBR;
|
||||||
ratecontrol_desc = "constant bitrate (CBR)";
|
ratecontrol_desc = "constant bitrate (CBR)";
|
||||||
} else if (!avctx->rc_max_rate) {
|
} else if (!avctx->rc_max_rate) {
|
||||||
q->param.mfx.RateControlMethod = MFX_RATECONTROL_AVBR;
|
#if QSV_VERSION_ATLEAST(1,7)
|
||||||
ratecontrol_desc = "average variable bitrate (AVBR)";
|
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 {
|
||||||
q->param.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
|
q->param.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
|
||||||
ratecontrol_desc = "variable bitrate (VBR)";
|
ratecontrol_desc = "variable bitrate (VBR)";
|
||||||
@ -132,6 +140,9 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case MFX_RATECONTROL_AVBR:
|
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.TargetKbps = avctx->bit_rate / 1000;
|
||||||
q->param.mfx.Convergence = q->avbr_convergence;
|
q->param.mfx.Convergence = q->avbr_convergence;
|
||||||
q->param.mfx.Accuracy = q->avbr_accuracy;
|
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;
|
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.ExtParam = q->extparam;
|
||||||
q->param.NumExtParam = FF_ARRAY_ELEMS(q->extparam);
|
q->param.NumExtParam = FF_ARRAY_ELEMS(q->extparam);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,12 @@ typedef struct QSVEncContext {
|
|||||||
mfxFrameAllocRequest req;
|
mfxFrameAllocRequest req;
|
||||||
|
|
||||||
mfxExtCodingOption extco;
|
mfxExtCodingOption extco;
|
||||||
|
#if QSV_VERSION_ATLEAST(1,6)
|
||||||
|
mfxExtCodingOption2 extco2;
|
||||||
|
mfxExtBuffer *extparam[2];
|
||||||
|
#else
|
||||||
mfxExtBuffer *extparam[1];
|
mfxExtBuffer *extparam[1];
|
||||||
|
#endif
|
||||||
|
|
||||||
AVFifoBuffer *async_fifo;
|
AVFifoBuffer *async_fifo;
|
||||||
|
|
||||||
@ -62,6 +67,9 @@ typedef struct QSVEncContext {
|
|||||||
int avbr_accuracy;
|
int avbr_accuracy;
|
||||||
int avbr_convergence;
|
int avbr_convergence;
|
||||||
int pic_timing_sei;
|
int pic_timing_sei;
|
||||||
|
int look_ahead;
|
||||||
|
int look_ahead_depth;
|
||||||
|
int look_ahead_downsampling;
|
||||||
|
|
||||||
char *load_plugins;
|
char *load_plugins;
|
||||||
} QSVEncContext;
|
} QSVEncContext;
|
||||||
|
@ -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 },
|
{ "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 },
|
{ "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" },
|
{ "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" },
|
{ "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" },
|
{ "baseline", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_AVC_BASELINE }, INT_MIN, INT_MAX, VE, "profile" },
|
||||||
|
Loading…
Reference in New Issue
Block a user