From patchwork Thu Nov 16 04:06:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: reito X-Patchwork-Id: 44682 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc9c:b0:181:818d:5e7f with SMTP id fx28csp155140pzb; Wed, 15 Nov 2023 20:07:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUBQkwPmd0NT0VWMLkF4miO2iq5wA1JolNBi2QAADarbpZh3tUBoZefV2lbFK+ka4FlCbh X-Received: by 2002:aa7:c9d9:0:b0:544:1fa7:b6c1 with SMTP id i25-20020aa7c9d9000000b005441fa7b6c1mr11041124edt.0.1700107636700; Wed, 15 Nov 2023 20:07:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700107636; cv=none; d=google.com; s=arc-20160816; b=rJHNjUicS5qDJUvxrDm2ZkSPD2f4VXmfCG/2ue1gVLXCIT1EwnTTbl9p50fZYGIq7v VDKuYQXhxEbKdvyW80yU2/Vv26i4hptOcKezHknADgWX3Ep4dBkzLoC6+6/wv6zP19iS jUgDt89R1c3g0FQz3eTy6nL/yCKAKeQ3hTgpSmNepg9SQnR//UhfyIO5HVkSMq4+qvjW tmrXrVsq5QmhzA0W6JJ3aRQVJtM0nzERObI5h623gu2qwjcxX/oi1e2lXm40dv4CsERx zTxNX+SPqdF0VHXiLAtPIEnpSTbbgKFbI9nQl5fO5JW05pxMt9UDhCMd8aKpWbnBsCcV 64Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:content-language:thread-index :mime-version:date:to:message-id:delivered-to; bh=AN0ww/7xttif2KZ54a8gD5EIFC4//a39daeK+3HUisQ=; fh=nyYfJcgpt8BOT+VEJw0l9svenrCXCvdgRwSUganox5U=; b=ZxPvpoRIk5eAI9FGV0zyqmCg2YqPofe99c1qGLnssMHZcs3BVDcMNgkD56qIpdGfg+ s74RYjSrURBBZC+4V42UjZLMkEhlXapAdxxoPCptNWWqI6AQUsaUmwMcHjSGCUTuh6rT eP4/maaSCVKSLBDff5al3Gz57dlrFwF0L7pVG+nag3FURC+APf/1g4Ns3xWnXrREyIee vNEWZAmkemWOJFw8Paby938J2ILP+rLT0E8Av8ktdj4mSk54kR0yVniDSFz6cmQ/jX0u MOd1fGN6kOUbaVVmMhn1HZCW7hjratFIU2MHx47g2ZT7oa++yr18ykA9YHuo+KPp/vr4 vonw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r24-20020a50d698000000b0054561bf6aa7si6536819edi.113.2023.11.15.20.07.16; Wed, 15 Nov 2023 20:07:16 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0AA9E68CD2D; Thu, 16 Nov 2023 06:07:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out162-62-57-64.mail.qq.com (out162-62-57-64.mail.qq.com [162.62.57.64]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1DF3B68C9F8 for ; Thu, 16 Nov 2023 06:07:03 +0200 (EET) Received: from Reito ([240e:388:18b2:4800:1424:d12b:b1f0:71ed]) by newxmesmtplogicsvrsza10-0.qq.com (NewEsmtp) with SMTP id 1BA28014; Thu, 16 Nov 2023 12:06:58 +0800 X-QQ-mid: xmsmtpt1700107619thd62clva Message-ID: X-QQ-XMAILINFO: OKkKo7I1HxIervRhJ3L51DuSymrmcqtCi13tdKChe7uBRzNVLaRSIIStiOfc0f 7RHweopMzEdysxzrjsKGmTgH6kyrcTimU+mZvDjnjn4YpqrbLtiqvJ7mI0ocVEwsZYBEsqfJ4HWa KlU9xHZBLCT8wc3zs+MLlFgzk2Qi8SRWIWx28BbivIYLnX2RVYVX3uGIHQVWJmJYXkABTxC47eAr JiZLV6/m/NFQ5rGuRprlUA21zWV6ABWVBI3UhVLKUZmV00sB4Rq0m+Q7HIMZ7fgWVzJ/Vy1IoJay o0rVvlXafS2EDy2z1q2QQPc8DB6be2NXUxYHYSm8AqRrdlJygOTzwmWbue6mnR9erE3UChkVRpvj iTy1Xdi28YsoZgLnmoakcWVLoIiEm9dWiDCM83mjSvNqiz8YVrugAetufy9rfwTqBp+nh2iApLiS Qp3ukXHI7YgUqFnFvD+fg2UdsEffZzRTI7aXIZMNru2ftN+Gg/ItwPw1CxA7xFRcWTI4chTrNteZ VyqhtztNb3E1BFLKv3oSiIKMLszkzLkUchMgQN+8oZZB0Z5mrCa3+yg2gtAqtK/78UHVRJ07mI1c xknGhr5fZaXGbhkcvo9FkL0PwwLjYZpuvZ3drZOvHgHnsqD9PKXFkHzaSsIVGKaiL39CxMXsuRau pq2lDqAgPPFmEdVU5jrWue8SgEMTiE+5YCDZP/FUQXPMqgIYptV9sPlglhWR2qlD2U2Mrrd0ZRxy HtSC0wntZvnoeblAmSqgWi/w+8+WcvdSDSn2e19wqKZyXeFHu80LYb6kSZC4WuUkEq4aGRPNIjgZ RPHsv8CvSq4L4q2L8ZDU7FK8vumQ6Fm70S/RueI6FkZJt0jIehOK5V35vlBis4lR9w7k1mRvJbpg Hf/R7Z3REO9BdlUOSd6wuub2D1Rf7dVLaVMwtEzuxx94X7g+OwBXsurpZ97TnKuWKxR+v+XRjOuQ /w6NiynSDlzeAL9il/8jOENss63rEDzW485K1A9sEBtIdhTpGXYZUC8sJWR6p7LnXYim1BrAFyHR C+/5R/AEHKDe4ofHms X-QQ-XMRINFO: Nq+8W0+stu50PRdwbJxPCL0= To: Date: Thu, 16 Nov 2023 12:06:56 +0800 X-OQ-MSGID: <000101da1842$57d2c570$07785050$@qq.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdoYQSfEsqWJJHvFTde54CORH8A+xw== Content-Language: zh-cn X-Antivirus: Avast (VPS 231115-10, 2023/11/16), Outbound message X-Antivirus-Status: Clean Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/qsv: add sps pps header when frame->key_frame is true X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Zhongwei Wang via ffmpeg-devel From: reito Reply-To: FFmpeg development discussions and patches Cc: Zhongwei Wang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 8R/sHHPRdcjk The key_frame currently doesn't set extra header into frames when using qsv encoders. Signed-off-by: reito --- libavcodec/qsvenc.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) + 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 && 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; +}