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: 44683 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc9c:b0:181:818d:5e7f with SMTP id fx28csp155185pzb; Wed, 15 Nov 2023 20:07:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCQyd33dklRMQYgNz4jWto3U+Lad674erPp0Zq9PUeyZ5MWIrXH1yO1eSrnKU+3pc3Dbc9 X-Received: by 2002:a05:6402:68c:b0:545:54fa:a808 with SMTP id f12-20020a056402068c00b0054554faa808mr12843303edy.33.1700107647380; Wed, 15 Nov 2023 20:07:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700107647; cv=none; d=google.com; s=arc-20160816; b=C0agojp2eeJxG+WIgYe7ZmuKmYk14/ckbicKFKWsCjD7mQ2kgO7HS2gCxfC3ok5YBt HmBy0Yb9KcBhNMw/yYT6AauSCAT4qZS8Y49cOE4wWW9xKLXdsaSrZOs0vkRDnK6r8Vra jcLl/FndumSDAwZxdPXyf478YUBZ0bGUo/2HoAUnIUQqbVHyu6CcaWjKqH9kZdP5SX8j UjnDv2QxVnma1LnXunnfdnQm9t08NPyn/aZFHlP/J5eH851ENaeXhEeypJuXDhbJtGb5 5cUaQFG1Efr7NXbV7floWdftdZBRMknZyuxIYwum5/ZLBA3Mfah/Wyt2GrlfyPBTM2uv pPTA== 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=nZLxSEIjCwxegU6ObJzbwXHAVbzU5BF+tqLGfpQRYFg=; fh=Xx3/cGrJJwpLgkx38yZQBhATwttwUeg63YaMxMLC9nM=; b=bC/QP5/5o8wAn3JpqhDI8MurAbAHMlXYtlzgmx31qg72vwtDOqDPpyJTA9e7ATRbz8 G63jZ26Yy1UiAP2R/LBhm+4gM2K0EgFnF+Pu2F+TuExQZ/21HFea9Wx6ul2kQ9l61JSK SNNNtvqZxCFoHiqrhsQNUsCroKQhKTLPQBSU3hgW9VVIxIvHTA2C3TMG3EvhAI213AXA Ixw/4rpsxBihw77LP26MYTCKB97+Tcitu7DjCYjuzLIxUmlboQgFt0+CZU8aYMgMGuL2 ivmU+fnpZIi5Hng5I0t8FDfz84Y45vI5TZSlo6/Pw6VtmfoFiEESXPg00nkBr9mZrqI5 9pIA== 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 v10-20020a50d08a000000b005435a921d6fsi6295203edd.239.2023.11.15.20.07.26; Wed, 15 Nov 2023 20:07:27 -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 53CAD68CD38; Thu, 16 Nov 2023 06:07:13 +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 293BD68CB56 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: xmsmtpt1700107618teoj0sjqj Message-ID: X-QQ-XMAILINFO: MAiknbc9razuJXFq7Ew7zAkavXGvfZvS5LDnV+QNjGuanqM6fkmbdqWFTBOz+N 7hZQjzjB86oKm8/FQVt+QwFxpzfawVsvN1HRbKIf8rqWltM4q4eJAI7aMSqyGvHeUecc5rvwgzoA o8HJ/KjnVqETzPSp7GNJoUndh35ELY+ZdsGq+VYv3fU8v721igL1q7u+uQMyL3zHd/v+KbYTLoMK JhZOFBxrS1wk+3CG6bojXN2h3OcBJtCgplVc3mR8lEPdab/9K1a7eXEKKjU/gPd3ejfoE3h7Bh2Z MkKeGOEh7n434HeB9YosuokErO6ElVamKfUWOOO9RqcCNGR//p7hRF30fxTVH5avyU/7GDio3zpE bV6qrf70S632laMgUsraRNsfz0tx63zfQVXYb7x9R80bgCBr2LYSHKX2UqgyKIakDBDCrtHH+7hd kM7O6YNZ0xNPyLPEqUbYUS3+ObZ2Ak7BufP8ZZW6u4CW5acrAWsLMF9RJMevodne1W4HZJ82jE1v /3/7BDfcElEzocDygl7yEtWbBw+vauSwMsacF5NMf+sHov2dc9ZJDjQE5HQSvqn6gK41955J/SJE oSOT4pBB9XxC5inuzeu/BuvVf11F07E2VdCHFbxdKAgvDAmRmOpFmyF9YhhNyzEhme+fBuhD1e9z v2zN34O7zzl9qdkrZH9+/e+Mf+GFClR4SJgyDBBn0C1pjsx/klfA6eQCWCfax2oMXv3uYDoYNoAv UPA8P89I+ymRgB0dx1NH8TycWsREUJ+UL+JWycuzTntd96PxZ5OdtkFy35rVRpnGmJsR3OW3vSmV FE4l5SxYDXW8xnYk3YunglvDznyT07IfD6Pw7O2htmYxjBlD6XME1SeKpIk1XLB6lxXThQslXaIj QFQBjZPMvpFpKRak+X2BATFK2biKK7Z4k/2JNUJ0SAHd6+mAGkC8lnQJzreppPlEhSdnj+HMNUPk //xxJnY/brPfOraj0mpUTgQMXXowXu3NK1f6PIenbiAtqMsM0XzNa1TS7oeZrGF0t2JRldkHW8Fs p3ZqMR1xPJrMVYVdTb9QUtjDAmtqA= X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= To: Date: Thu, 16 Nov 2023 12:06:56 +0800 X-OQ-MSGID: <000001da1842$578b8340$06a289c0$@qq.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdoYQW4aV9geTungRMmUmuFQyypAeA== Content-Language: zh-cn X-Antivirus: Avast (VPS 231115-10, 2023/11/16), Outbound message X-Antivirus-Status: Clean Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/amd: fix pict_type, match it with amf & ffmpeg. add sps pps when frame->keyframe 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: reito via ffmpeg-devel From: reito Reply-To: FFmpeg development discussions and patches Cc: reito Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ENVVHG0hWDS/ The frame->key_frame currently doesn't set extra header into frames when using amf encoders. The frame->pict_type is not set to amf picture type, now we force it. Signed-off-by: reito --- libavcodec/amfenc.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) AMF_VIDEO_ENCODER_HEVC_PICTURE_TYPE_SKIP); + break; + default: + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_HEVC_PICTURE_TYPE_NONE); + break; + } + // Keyframe overrides previous assignment. + if (frame->key_frame) { + av_log(ctx, AV_LOG_DEBUG, "IDR,PPS and SPS set - h265\n"); + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_INSERT_HEADER, 1); + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_HEVC_PICTURE_TYPE_IDR); + } + } + // submit surface res = ctx->encoder->pVtbl->SubmitInput(ctx->encoder, (AMFData*)surface); if (res == AMF_INPUT_FULL) { // handle full queue diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index 061859f85c..076fecb760 100644 --- a/libavcodec/amfenc.c +++ b/libavcodec/amfenc.c @@ -696,6 +696,58 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt) break; } + // Override Picture Type for Frame + if (avctx->codec->id == AV_CODEC_ID_H264) { + switch (frame->pict_type) { + case AV_PICTURE_TYPE_I: + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_PICTURE_TYPE_I); + break; + case AV_PICTURE_TYPE_P: + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_PICTURE_TYPE_P); + break; + case AV_PICTURE_TYPE_B: + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_PICTURE_TYPE_B); + break; + case AV_PICTURE_TYPE_S: + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_PICTURE_TYPE_SKIP); + break; + default: + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_PICTURE_TYPE_NONE); + break; + } + // Keyframe overrides previous assignment. + if (frame->key_frame) { + av_log(ctx, AV_LOG_DEBUG, "IDR,AUD,PPS and SPS set - h264\n"); + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_INSERT_SPS, 1); + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_INSERT_PPS, 1); + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_PICTURE_TYPE_IDR); + } + } else if (avctx->codec->id == AV_CODEC_ID_HEVC) { + switch (frame->pict_type) { + case AV_PICTURE_TYPE_I: + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_HEVC_PICTURE_TYPE_I); + break; + case AV_PICTURE_TYPE_P: + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_FORCE_PICTURE_TYPE, AMF_VIDEO_ENCODER_HEVC_PICTURE_TYPE_P); + break; + case AV_PICTURE_TYPE_B: + av_log(ctx, AV_LOG_WARNING, "Ignoring B-Frame, unsupported by AMD AMF H.265 Encoder."); + break; + case AV_PICTURE_TYPE_S: + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_FORCE_PICTURE_TYPE,