mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-08-12 13:23:48 +00:00
When a CUDA frame with a supported RGB sw_format is received, map the GPU device pointer directly into a LibTorch tensor using torch::from_blob() with CUDA device options, bypassing cudaMemcpy entirely. Changes: - Add fill_model_input_cuda() that extracts the CUdeviceptr from the AVHWFramesContext and wraps it in a PyTorch GPU tensor with a no-op deleter (memory owned by FFmpeg AVBuffer ref-counting). - Handle GPU memory alignment padding via custom strides derived from AVFrame linesize. - Permute the mapped NHWC tensor to NCHW (PyTorch convention). - Manage CUDA context explicitly with cuCtxPushCurrent/cuCtxPopCurrent for thread safety in async filter graphs. - Implement zero-copy Device-to-Device output mapping that writes the model result directly into the output frame's VRAM, bypassing ff_proc_from_dnn_to_frame / sws_scale entirely for CUDA frames. - Add torch::cuda::synchronize() to prevent async race conditions with downstream encoders (e.g. NVENC reading uninitialized frames). - Add format validation in ff_dnn_zero_copy_supported_cuda() to reject unsupported sw_formats and batching with CUDA zero-copy early. - Register AV_PIX_FMT_CUDA in vf_dnn_processing pixel format list. - Gracefully fall back to CPU path when sw_format is not a supported RGB variant or when CONFIG_CUDA is not enabled. Signed-off-by: Raja-89 <imraja729@gmail.com>