How to use cv::cudacodec::createVideoReader on Jetson Orin NX

Hello,

We are using a Jetson Orin NX 16Gb developer kit for object detection tasks.
We would like to use OpenCV’s cv::cudacodec::createVideoReader function, to decode videofiles using the GPU and placing the frames directly into GPU memory (instead of loading them into CPU memory and then copying them to GPU memory).

However, our C++ code crashes at runtime when creating the video_reader object, with this error:

terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.10.0) /home/username/Desktop/opencv-install-2025/opencv_contrib/modules/cudacodec/src/video_reader.cpp:190: error: (-217:Gpu API call) Unknown error code [Code = -841547496] in function 'VideoReaderImpl'

OpenCV version 4.10.0 is compiled with the following options:

  NVIDIA CUDA:                   YES (ver 12.6, CUFFT CUBLAS NVCUVID NVCUVENC)
    NVIDIA GPU arch:             87
    NVIDIA PTX archs:

  cuDNN:                         YES (ver 9.3.0)

The C++ code is as follows:

#include <iostream>
#include <chrono>
#include <opencv2/opencv.hpp>
#include <opencv2/cudacodec.hpp>
#include <opencv2/core/cuda.hpp>

int main(int argc, char** argv) {
        // Print OpenCV version and build information
        std::cout << "OpenCV Version: " << CV_VERSION << std::endl;
        std::cout << cv::getBuildInformation() << std::endl;

        // video reader parameters
        std::vector<int> sourceParams = {
                cv::CAP_PROP_OPEN_TIMEOUT_MSEC, 5000,  // Open timeout of 5 seconds
                cv::CAP_PROP_READ_TIMEOUT_MSEC, 3000  // Read timeout of 3 seconds
        };

        cv::cudacodec::VideoReaderInitParams initParams;
        initParams.rawMode = false; // Decode frames
        initParams.targetSz = cv::Size(1280, 720); // Resize decoded frames to 1280x720
        initParams.allowFrameDrop = true; // Allow frame drops
        initParams.minNumDecodeSurfaces = 4; // Use 4 decode surfaces

        // video reader object
        cv::Ptr<cv::cudacodec::VideoReader> video_reader = cv::cudacodec::createVideoReader("/home/username/Desktop/recording-h264.mp4", sourceParams, initParams); // code crashes here at runtime

        cv::cuda::GpuMat gpu_frame;

        while (video_reader->nextFrame(gpu_frame)) {
                // Loop over video file
        }

        return 0;
}

The Jetson has a fresh install with Jetpack 6.2 (L4T 36.4.3):
CUDA: 12.6.68
cuDNN: 9.3.0.75
TensorRT: 10.3.0.30

It is unclear to us why this is not working. Any help would be much appreciated!

Hi,
cv::cudacodec is not supported on Jetson platforms, since there are individual hardware codec engines in Jetson SoC. For this use-case, would suggest check
GitHub - dusty-nv/jetson-inference: Hello AI World guide to deploying deep-learning inference networks and deep vision primitives with TensorRT and NVIDIA Jetson.