Skip to content

Dynamically load nvcuvid library? #978

@traversaro

Description

@traversaro

🚀 The feature

It would be great if torchcodec dynamically loaded the nvcuvid library instead of directly linking it, or at least have an option to dynamically load the nvcuvid library instead of directly link it.

Motivation, pitch

First of all, thanks a lot for the great work on the new NVCUVID backend (#910 and following PRs). I looked into that as part of the 0.8.0, and I noticed that currently we directly link the nvcuvid library in

.

This specific choice works great in most cases, but in some corner cases can be problematic (that problably only emerge in conda-forge packaging and hence why I stumbled on them), in particular:

  • On some Linux NVIDIA system without NVDEC silicon (such as Tegra/Jetson Orin), the libnvcuvid.so library is not installed as part of the system driver. So, that always meant that torchcodec's GPU capabilities were not working, but at least before 0.8.0 it was possible to use a torchcodec CUDA build to actually do CPU decoding, as libnvcuvid.so library was not required unless ffmpeg was actually requested to use _cuvid decoder. After 0.8.0 instead, for a torchcodec CUDA build, it is required for libnvcuvid.so to be present in the system, otherwise the libtorchcodec_core7.so can't be loaded at all, preventing the use of torchcodec even just for CPU usage.
  • On Windows to actually link the nvcuvid.dll library, you also need the nvcuvid.lib import library, that is not installed by the NVIDIA driver as nvcuvid.dll, but it installed separately by the "Video Codec for application developers", that needs to be manually downloaded from https://developer.nvidia.com/nvidia-video-codec-sdk/download by accepting the " NVIDIA Software Developer License Agreement". This is different from Linux, there the libnvcuvid.so is the one installed in the system, but that can also be used when linking the library.

How does other projects like ffmpeg or dali deal with this? Instead of directly linking to nvcuvid library, they dynamically load nvcuvid, gracefully raising an error if the library can't be loaded, see:

If there is interested for something like that I probably can also contribute in that direction, even if I can't provide a definite timeframe for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions