avutil/hwcontext: pool the frames av_hwframe_transfer_data() allocates

A destination frame without buffers was allocated anew for every
download. For large frames the allocation costs more than the
transfer.

ffmpeg -hwaccel cuda -i hevc.mp4 -f null - on a RTX 5090, mean of 10
runs: 2160p 390 -> 497 fps, 4320p 33 -> 112 fps, 1080p unchanged at
1772 fps.

Assisted-by: Claude
This commit is contained in:
Michael Niedermayer authored and michaelni committed 2026-10-21 19:32:23 +00:00
1 parent b8249f73a7
commit 5ac6d116e7
2 files changed
+2 -2

No files matched your search

+1 -1
View File
@@ -461,7 +461,7 @@ static int transfer_data_alloc(AVFrame *dst, const AVFrame *src, int flags)
frame_tmp->width = ctx->width;
frame_tmp->height = ctx->height;
ret = av_frame_get_buffer(frame_tmp, 0);
ret = av_hwframe_get_transfer_buffer(src->hw_frames_ctx, frame_tmp);
if (ret < 0)
goto fail;
+1 -1
View File
@@ -399,7 +399,7 @@ int av_hwframe_get_transfer_buffer(AVBufferRef *hwframe_ctx, AVFrame *frame);
* AV_HWFRAME_TRANSFER_DIRECTION_TO)
*
* dst may be "clean" (i.e. with data/buf pointers unset), in which case the
* data buffers will be allocated by this function using av_frame_get_buffer().
* data buffers will be allocated by this function.
* If dst->format is set, then this format will be used, otherwise (when
* dst->format is AV_PIX_FMT_NONE) the first acceptable format will be chosen.
*