What is the best way to decode a MJPEG stream by using GPU to feed an OpenCV application?

Hi everyone,
I have wrote an OpenCV application in Qt (MSVC 2017) to decode raw frames from a MJPEG steam for further process, now I am trying to use GPU for decoding the stream. what is the best and easiest way to do so?

1 Like

Hi,

You can use NVIDIA Video Codec SDK. Please download the package from NVIDIA VIDEO CODEC SDK | NVIDIA Developer. We have samples which illustrate JPEG decoding, which you can refer to.

Let us know if you need more help.

Thanks,
Ryan Park

1 Like

Hi,

Thank you, I used the mentioned SDK and recompiled OpenCV with NVCUVID support. now I can use opencv gpu video decoder :).

1 Like

I am trying to decode a MJPEG frame from a camera.

@pouya.ahmadvand - can you please elaborate recompiling opencv with NVCUVID ?

what are the switches/options you used? my understanding was NVCUVID was deprecated.

also, for the cuda gpu decoder you are referring to, are you using cudacodec::VideoReader ?

finally are you reading video files or reading from camera?

thanks a lot for any help.

Yes, you must download nvidia codec sdk separately and recompile opencv (4.0.1) by NVCUVID. You can follow this link :

https://github.com/opencv/opencv_contrib/pull/1946

Yes I’m using cudacodec::VideoReader to decode a camera stream

1 Like

Thanks!

did you implement your own cudacodec::RawVideoSource or how are you reading from camera?

is it USB or RTSP stream or other camera sources?

1 Like

Don’t use OpenCV, it will add more latency and make the project useless as you will continue to get ridiculous amount of deprecations and incompatibilities. Keep it simple and use basic direct libraries without OpenCV. OpenCV needs to start making their massive library into discrete buildable libraries.

Can you please show references where exactly how Codec SDK uses GPU to decode MJPEG?

I have a RTX 3080 TI, can not find any info on how to decode MJPEG 100% in GPU and not on CPU. I program in C/C++ and the nvdecoder.cpp and header files in the sample folder have no meaningful info in MJPEG decoding, no programmatic arguments for it. Weird.

I know that Nvidia PureVideo HD SIP component does not have MJPEG decoder, however what about CUDA cores? Couldn’t Nvidia provide a MJPEG decoder implemented in CUDA core? I have multiple cameras and decoding in CPU is not favorable.

Thanks.