[FFmpeg-devel] [PATCH 1/2] avcodec/qsv: add sps pps header when frame->key_frame is true
Zhongwei Wang
cnschwarzer at qq.com
Thu Nov 16 06:06:56 EET 2023
The key_frame currently doesn't set extra header into frames when using qsv
encoders.
Signed-off-by: reito <cnschwarzer at qq.com>
---
libavcodec/qsvenc.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index a0144b0760..2bd85a2f91 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -2365,6 +2365,28 @@ static int update_pic_timing_sei(AVCodecContext
*avctx, QSVEncContext *q)
return updated;
}
+static int set_sps_pps_encode_ctrl(AVCodecContext *avctx, const AVFrame
*frame,
+ mfxEncodeCtrl *enc_ctrl)
+{
+ mfxExtInsertHeaders *insert_headers = NULL;
+
+ if (frame->key_frame) {
+ av_log(avctx, AV_LOG_DEBUG, "Insert SPS PPS Header because of
key_frame == 1\n");
+ insert_headers = av_mallocz(sizeof(*insert_headers));
+ if (!insert_headers)
+ return AVERROR(ENOMEM);
+ insert_headers->Header.BufferId = MFX_EXTBUFF_INSERT_HEADERS;
+ insert_headers->Header.BufferSz = sizeof(*insert_headers);
+ insert_headers->SPS = MFX_CODINGOPTION_ON;
+ insert_headers->PPS = MFX_CODINGOPTION_ON;
+
+ enc_ctrl->ExtParam[enc_ctrl->NumExtParam] = (mfxExtBuffer
*)insert_headers;
+ enc_ctrl->NumExtParam++;
+ }
+
+ return 0;
+}
+
static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
const AVFrame *frame)
{
@@ -2434,6 +2456,15 @@ static int encode_frame(AVCodecContext *avctx,
QSVEncContext *q,
if (ret < 0)
goto free;
}
+
+ if ((avctx->codec_id == AV_CODEC_ID_H264 ||
+ avctx->codec_id == AV_CODEC_ID_H265) &&
+ enc_ctrl && QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 34)) {
+ ret = set_sps_pps_encode_ctrl(avctx, frame, enc_ctrl);
+ if (ret < 0)
+ goto free;
+ }
+
if ((avctx->codec_id == AV_CODEC_ID_H264 ||
avctx->codec_id == AV_CODEC_ID_H265) &&
q->skip_frame != MFX_SKIPFRAME_NO_SKIP &&
--
2.38.1.windows.1
--
这封电子邮件已由 Avast 防病毒软件检查过病毒。
www.avast.com
More information about the ffmpeg-devel
mailing list