[FFmpeg-devel] [PATCH] avcodec/amfenc: Add support for on-demand key frames
Lynne
dev at lynne.ee
Fri Sep 6 00:27:40 EEST 2024
On 05/09/2024 07:16, Cameron Gutman wrote:
> Signed-off-by: Cameron Gutman <aicommander at gmail.com>
> ---
> libavcodec/amfenc.c | 34 +++++++++++++++++++++++++++++++++-
> 1 file changed, 33 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
> index 41eaef9758..6f2b211d14 100644
> --- a/libavcodec/amfenc.c
> +++ b/libavcodec/amfenc.c
> @@ -766,11 +766,43 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
> switch (avctx->codec->id) {
> case AV_CODEC_ID_H264:
> AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_INSERT_AUD, !!ctx->aud);
> + if (frame->flags & AV_FRAME_FLAG_KEY) {
> + 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 {
> + 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;
> + }
> + }
> break;
> case AV_CODEC_ID_HEVC:
> AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_HEVC_INSERT_AUD, !!ctx->aud);
> + if (frame->flags & AV_FRAME_FLAG_KEY) {
> + 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);
> + } else {
> + 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;
> + }
> + }
> + break;
> + case AV_CODEC_ID_AV1:
> + if (frame->flags & AV_FRAME_FLAG_KEY) {
> + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_AV1_FORCE_INSERT_SEQUENCE_HEADER, 1);
> + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_AV1_FORCE_FRAME_TYPE, AMF_VIDEO_ENCODER_AV1_FORCE_FRAME_TYPE_KEY);
> + } else if (frame->pict_type == AV_PICTURE_TYPE_I) {
> + AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_ENCODER_AV1_FORCE_FRAME_TYPE, AMF_VIDEO_ENCODER_AV1_FORCE_FRAME_TYPE_INTRA_ONLY);
> + }
> break;
> - //case AV_CODEC_ID_AV1 not supported
> default:
> break;
> }
You should hook up FFCodec.flush instead. That's what nvenc uses to
reset the GOP.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0xA2FEA5F03F034464.asc
Type: application/pgp-keys
Size: 624 bytes
Desc: OpenPGP public key
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20240905/deab1944/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20240905/deab1944/attachment.sig>
More information about the ffmpeg-devel
mailing list