From: Zhongwei Wang via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: <ffmpeg-devel@ffmpeg.org> Cc: Zhongwei Wang <cnschwarzer@qq.com> Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/qsv: add sps pps header when frame->key_frame is true Date: Thu, 16 Nov 2023 12:06:56 +0800 Message-ID: <tencent_FABD9090880A1848FFE300455C9E0299AA08@qq.com> (raw) The key_frame currently doesn't set extra header into frames when using qsv encoders. Signed-off-by: reito <cnschwarzer@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 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2023-11-16 4:07 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-11-16 4:06 Zhongwei Wang via ffmpeg-devel [this message] 2023-11-16 22:41 ` Michael Niedermayer 2023-11-29 7:26 ` Xiang, Haihao
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=tencent_FABD9090880A1848FFE300455C9E0299AA08@qq.com \ --to=ffmpeg-devel@ffmpeg.org \ --cc=cnschwarzer@qq.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git