Message ID | 1571126183-23230-1-git-send-email-linjie.fu@intel.com |
---|---|
State | Accepted |
Commit | e786e37326d4274c1dfbc37a6478680684c779c9 |
Headers | show |
> -----Original Message----- > From: Fu, Linjie <linjie.fu@intel.com> > Sent: Tuesday, October 15, 2019 15:56 > To: ffmpeg-devel@ffmpeg.org > Cc: Fu, Linjie <linjie.fu@intel.com> > Subject: [PATCH] lavc/qsvenc: Fix bitrate_limit to allow AVC encode in limited > bitrate > > MFXVideoENCODE_Query calls CheckVideoParamQueryLike in MSDK and > will determine whether to set param.mfx.TargetKbps to the allowed > minTargetKbps according to the bitrate_limit in extco2 buffer. > > Thus q->param.ExtParam must be set before MFXVideoENCODE_Query in > case > minTargetKbps is written to TargetKbps by default. > > 1080P AVC encoding with option "-bitrate_limit 0 -b:v 100k": > Before patch: > 902 kbps > After patch: > 156 kbps > Signed-off-by: Linjie Fu <linjie.fu@intel.com> > --- > libavcodec/qsvenc.c | 38 +++++++++++++++++++------------------- > 1 file changed, 19 insertions(+), 19 deletions(-) Ping. This is reported by Mann, J in: https://software.intel.com/en-us/forums/intel-media-sdk/topic/815938 - linjie
> -----Original Message----- > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Fu, > Linjie > Sent: Friday, October 18, 2019 16:50 > To: FFmpeg development discussions and patches <ffmpeg- > devel@ffmpeg.org> > Subject: Re: [FFmpeg-devel] [PATCH] lavc/qsvenc: Fix bitrate_limit to allow > AVC encode in limited bitrate > > > -----Original Message----- > > From: Fu, Linjie <linjie.fu@intel.com> > > Sent: Tuesday, October 15, 2019 15:56 > > To: ffmpeg-devel@ffmpeg.org > > Cc: Fu, Linjie <linjie.fu@intel.com> > > Subject: [PATCH] lavc/qsvenc: Fix bitrate_limit to allow AVC encode in > limited > > bitrate > > > > MFXVideoENCODE_Query calls CheckVideoParamQueryLike in MSDK and > > will determine whether to set param.mfx.TargetKbps to the allowed > > minTargetKbps according to the bitrate_limit in extco2 buffer. > > > > Thus q->param.ExtParam must be set before MFXVideoENCODE_Query in > > case > > minTargetKbps is written to TargetKbps by default. > > > > 1080P AVC encoding with option "-bitrate_limit 0 -b:v 100k": > > Before patch: > > 902 kbps > > After patch: > > 156 kbps > > Signed-off-by: Linjie Fu <linjie.fu@intel.com> > > --- > > libavcodec/qsvenc.c | 38 +++++++++++++++++++------------------- > > 1 file changed, 19 insertions(+), 19 deletions(-) > > Ping. > This is reported by Mann, J in: > https://software.intel.com/en-us/forums/intel-media-sdk/topic/815938 > > - linjie Ping. - linjie
Applied.
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index ba85d64..dcff778 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -1052,25 +1052,6 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q) if (ret < 0) return ret; - ret = MFXVideoENCODE_Query(q->session, &q->param, &q->param); - if (ret == MFX_WRN_PARTIAL_ACCELERATION) { - av_log(avctx, AV_LOG_WARNING, "Encoder will work with partial HW acceleration\n"); - } else if (ret < 0) { - return ff_qsv_print_error(avctx, ret, - "Error querying encoder params"); - } - - ret = MFXVideoENCODE_QueryIOSurf(q->session, &q->param, &q->req); - if (ret < 0) - return ff_qsv_print_error(avctx, ret, - "Error querying (IOSurf) the encoding parameters"); - - if (opaque_alloc) { - ret = qsv_init_opaque_alloc(avctx, q); - if (ret < 0) - return ret; - } - if (avctx->hwaccel_context) { AVQSVContext *qsv = avctx->hwaccel_context; int i, j; @@ -1100,6 +1081,25 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q) q->param.NumExtParam = q->nb_extparam_internal; } + ret = MFXVideoENCODE_Query(q->session, &q->param, &q->param); + if (ret == MFX_WRN_PARTIAL_ACCELERATION) { + av_log(avctx, AV_LOG_WARNING, "Encoder will work with partial HW acceleration\n"); + } else if (ret < 0) { + return ff_qsv_print_error(avctx, ret, + "Error querying encoder params"); + } + + ret = MFXVideoENCODE_QueryIOSurf(q->session, &q->param, &q->req); + if (ret < 0) + return ff_qsv_print_error(avctx, ret, + "Error querying (IOSurf) the encoding parameters"); + + if (opaque_alloc) { + ret = qsv_init_opaque_alloc(avctx, q); + if (ret < 0) + return ret; + } + ret = MFXVideoENCODE_Init(q->session, &q->param); if (ret < 0) return ff_qsv_print_error(avctx, ret,
MFXVideoENCODE_Query calls CheckVideoParamQueryLike in MSDK and will determine whether to set param.mfx.TargetKbps to the allowed minTargetKbps according to the bitrate_limit in extco2 buffer. Thus q->param.ExtParam must be set before MFXVideoENCODE_Query in case minTargetKbps is written to TargetKbps by default. 1080P AVC encoding with option "-bitrate_limit 0 -b:v 100k": Before patch: 902 kbps After patch: 156 kbps Signed-off-by: Linjie Fu <linjie.fu@intel.com> --- libavcodec/qsvenc.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)