Preserving hardware memory during cuvid decoding, exporting/importing via dlpack.#2155
Preserving hardware memory during cuvid decoding, exporting/importing via dlpack.#2155caffeinism wants to merge 9 commits intoPyAV-Org:mainfrom
Conversation
|
@WyattBlue If I add tests, will it work fine even if it only runs on a CUDA machine? I don't think it will work in the GitHub workflow. |
|
You need to test the interface. For example, hw_format does not have an |
|
|
Could you please explain it in a bit more detail?
In this case, how should dlpack.pxd be handled? Should this also be moved to the include directory? |
|
@WyattBlue Could you take a look at the last commit section? I modified the buffer creation logic for frames generated by VideoFrame(), VideoFrame.from_ndarray(), and VideoFrame.reformat to support dlpack. |
#2148
Hello? I'm a user with limited knowledge of libav, dlpack, and cython. However, recognizing this as a necessary feature, I drafted this with the help of an LLM.
Motivation
If an application decodes video, performs GPU operations, and then re-encodes it, PyAV currently incurs a significant amount of memcopy. (GPU (cuvid) -> CPU (PyAV) -> GPU (Torch, etc.) -> CPU (PyAV) -> GPU (nvenc)) However, if we could export frames decoded by cuvid to dlpack while keeping them on the GPU, we wouldn't need to move the frames to CPU memory.
I passed all existing tests, but with such extensive modifications, it seems difficult for a beginner like me to catch every single detail. However, since most changes involve adding features rather than modifying existing ones, I hope this PR serves as a good starting point.
Usage example