Skip to content
No description, website, or topics provided.
C++ CMake
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
CMakeLists.txt
LICENSE
README.md
dynlink_nvcuvid.cpp
results.png
video_reader.cpp

README.md

opencv_gpu_video_reader

This is an OpenCV example, where video_reader.cpp is taken directly from opencv/samples/gpu and whipped into shape so it actually builds and runs.

The sample demonstrates performance improvement gained from using NVIDIA codec with OpenCV.

Code Modifications

In order to port this functionality to your application (as well as make the actual OpenCV sample run):

  1. Add dynlink_nvcuvid.cpp to your source
  2. Include the following:
#include <dynlink_nvcuvid.h>
  1. Use the following code to initialize NVCUVID
using namespace std;

// Init CUDA
void *hHandleDriver = nullptr;
CUresult cuda_res = cuInit(0, __CUDA_API_VERSION, hHandleDriver);
if (cuda_res != CUDA_SUCCESS)
{
    throw exception();
}
cuda_res = cuvidInit(0);
if (cuda_res != CUDA_SUCCESS)
{
    throw exception();
}

Building and Running

Prerequeisits

  1. Ubuntu 16.04 +
  2. CUDA 9.0 +
  3. OpenCV 3.3+
  4. OpenGL (optional, if you want to watch the video)
  5. OpenGL hooks for GTK, also optional

It is not necessary to install OpenGL, if not installing just comment out any UX-related lines in video_reader.cpp

Build

git clone https://github.com/fierval/opencv_gpu_video_reader.git
cd opencv_gpu_video_reader
mkdir build
cd build
cmake ..
make

Run

./video_reader <path_to_a_video>

Results

results

An order of magnitude improvement.

You can’t perform that action at this time.