Hello,
This patch makes nvenc copy incoming hwaccel frames instead of ref count
increase.
It fixes the bug which may happen when on-GPU transcoding is done and encoder
is set to use B frames.
How to reproduce the bug:
./ffmpeg \
-hwaccel cuda -hwaccel_output_format cuda \
-i input.mkv \
-c:v h264_nvenc -preset p4 -tune hq -bf 3 \
-y output.mkv
Expected output:
[h264 @ 0x55b14da4b4c0] No decoder surfaces left
[h264 @ 0x55b14da682c0] No decoder surfaces left
[h264 @ 0x55b14da850c0] No decoder surfaces left
[h264 @ 0x55b14daa1ec0] No decoder surfaces left
Error while decoding stream #0:0: Invalid data found when processing input
[h264 @ 0x55b14da2e6c0] No decoder surfaces left
Error while decoding stream #0:0: Invalid data found when processing input
Last message repeated 1 times
Although fix adds extra CUDA DtoD memcopy, our internal testing results didn't
show any noticeable difference in transcoding performance.
From c95adcf7d5f5dd787eaa80fa4643e7868f85848e Mon Sep 17 00:00:00 2001
From: Roman Arzumanyan <[email protected]>
Date: Tue, 14 Sep 2021 14:03:24 +0300
Subject: [PATCH] nvenc: copy incoming HW frame instead of referencing
---
libavcodec/nvenc.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 815b9429b3..9b4c968179 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1849,7 +1849,7 @@ static int nvenc_upload_frame(AVCodecContext *avctx, const AVFrame *frame,
return reg_idx;
}
- res = av_frame_ref(nvenc_frame->in_ref, frame);
+ res = av_hwframe_transfer_data(nvenc_frame->in_ref, frame, 0);
if (res < 0)
return res;
@@ -1858,7 +1858,6 @@ static int nvenc_upload_frame(AVCodecContext *avctx, const AVFrame *frame,
ctx->registered_frames[reg_idx].in_map.registeredResource = ctx->registered_frames[reg_idx].regptr;
nv_status = p_nvenc->nvEncMapInputResource(ctx->nvencoder, &ctx->registered_frames[reg_idx].in_map);
if (nv_status != NV_ENC_SUCCESS) {
- av_frame_unref(nvenc_frame->in_ref);
return nvenc_print_error(avctx, nv_status, "Error mapping an input resource");
}
}
@@ -2029,8 +2028,6 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencSur
goto error;
}
- av_frame_unref(tmpoutsurf->in_ref);
-
tmpoutsurf->input_surface = NULL;
}
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".