1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

libavcodec/qsvenc: Add low latency P-pyramid support to qsv

Add low latency P-pyramid support to qsv. This feature relates to
command line option "-p_strategy". To enable this flag, user also
need to set "-bf" to 0. P-strategy has two modes "1-simple" and
"2-pyramid". The details of the two models refer to
https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#preftype

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
This commit is contained in:
Wenbin Chen 2022-01-17 13:11:21 +08:00 committed by Haihao Xiang
parent 812b6ee6bd
commit 9d6cc6a544
3 changed files with 45 additions and 0 deletions

View File

@ -3296,6 +3296,9 @@ to allow changing of frame type from P and B to I.
@item @var{adaptive_b}
This flag controls changing of frame type from B to P.
@item @var{p_strategy}
Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).
@item @var{b_strategy}
This option controls usage of B frames as reference.
@ -3394,6 +3397,9 @@ Enable rate distortion optimization.
@item @var{max_frame_size}
Maximum encoded frame size in bytes.
@item @var{p_strategy}
Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).
@item @var{dblk_idc}
This option disable deblocking. It has value in range 0~2.

View File

@ -318,6 +318,14 @@ static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q,
case MFX_B_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "pyramid"); break;
default: av_log(avctx, AV_LOG_VERBOSE, "auto"); break;
}
av_log(avctx, AV_LOG_VERBOSE, "; PRefType: ");
switch (co3->PRefType) {
case MFX_P_REF_DEFAULT: av_log(avctx, AV_LOG_VERBOSE, "default"); break;
case MFX_P_REF_SIMPLE: av_log(avctx, AV_LOG_VERBOSE, "simple"); break;
case MFX_P_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "pyramid"); break;
default: av_log(avctx, AV_LOG_VERBOSE, "unknown"); break;
}
av_log(avctx, AV_LOG_VERBOSE, "\n");
#endif
@ -936,6 +944,34 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
#if QSV_HAVE_CO3
q->extco3.Header.BufferId = MFX_EXTBUFF_CODING_OPTION3;
q->extco3.Header.BufferSz = sizeof(q->extco3);
if (avctx->codec_id == AV_CODEC_ID_HEVC ||
avctx->codec_id == AV_CODEC_ID_H264) {
#if QSV_HAVE_PREF
switch (q->p_strategy) {
case 0:
q->extco3.PRefType = MFX_P_REF_DEFAULT;
break;
case 1:
q->extco3.PRefType = MFX_P_REF_SIMPLE;
break;
case 2:
q->extco3.PRefType = MFX_P_REF_PYRAMID;
break;
default:
q->extco3.PRefType = MFX_P_REF_DEFAULT;
av_log(avctx, AV_LOG_WARNING,
"invalid p_strategy, set to default\n");
break;
}
if (q->extco3.PRefType == MFX_P_REF_PYRAMID &&
avctx->max_b_frames != 0) {
av_log(avctx, AV_LOG_WARNING,
"Please set max_b_frames(-bf) to 0 to enable P-pyramid\n");
}
#endif
}
#if QSV_HAVE_GPB
if (avctx->codec_id == AV_CODEC_ID_HEVC)
q->extco3.GPB = q->gpb ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;

View File

@ -51,6 +51,7 @@
#define QSV_HAVE_LA_DS QSV_VERSION_ATLEAST(1, 8)
#define QSV_HAVE_LA_HRD QSV_VERSION_ATLEAST(1, 11)
#define QSV_HAVE_VDENC QSV_VERSION_ATLEAST(1, 15)
#define QSV_HAVE_PREF QSV_VERSION_ATLEAST(1, 16)
#define QSV_HAVE_GPB QSV_VERSION_ATLEAST(1, 18)
@ -95,6 +96,7 @@
{ "extbrc", "Extended bitrate control", OFFSET(qsv.extbrc), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, \
{ "adaptive_i", "Adaptive I-frame placement", OFFSET(qsv.adaptive_i), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, \
{ "adaptive_b", "Adaptive B-frame placement", OFFSET(qsv.adaptive_b), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, \
{ "p_strategy", "Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).", OFFSET(qsv.p_strategy), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 2, VE }, \
{ "b_strategy", "Strategy to choose between I/P/B-frames", OFFSET(qsv.b_strategy), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, \
{ "forced_idr", "Forcing I frames as IDR frames", OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 = 0 }, 0, 1, VE }, \
{ "low_power", "enable low power mode(experimental: many limitations by mfx version, BRC modes, etc.)", OFFSET(qsv.low_power), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, VE},\
@ -187,6 +189,7 @@ typedef struct QSVEncContext {
int adaptive_i;
int adaptive_b;
int b_strategy;
int p_strategy;
int cavlc;
int int_ref_type;