Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem with Intel Media SDK Backend for VideoCapture

Hey, so I installed "Intel Distribution of OpenVINO Toolkit" which, among other things, comes with an opencv version precompiled to be able to use hardware acceleration on Intel CPUs. I did the full installation on Linux (Ubuntu 18.04) and it ran without any problems.

Now, the single most important thing I need from this toolkit is the hardware accelerated video encoding and decoding in opencv.

To test this, I downloaded the 720p 30MB mp4 sample video from https://www.sample-videos.com/ and sucessfully used the code from https://www.learnopencv.com/read-write-and-display-a-video-using-opencv-cpp-python/ to decode, display and write it. Doing this pushed my CPU to 100% usage on all cores, monitored via htop.

Simply adding the CAP_INTEL_MFX backend Flag to the writer initialization as decribed in https://github.com/opencv/opencv/wiki/MediaSDK-encode-decode-backend, brought that down to about 70% usage:

int fourcc = VideoWriter::fourcc('H', '2', '6', '4'); VideoWirter video("outcpp.avi", CAP_INTEL_MFX, fourcc, 10, Size(frame_width, frame_height));

This, to me, suggests that hardware acceleration via the Media SDK indeed works for encoding the video.

Converting the .mp4 to .264 as described in https://github.com/opencv/opencv/wiki/MediaSDK-encode-decode-backend and then running the prgram WITHOUT Hardware acceleration on the VideoCapture object works as well.

But when I add the CAP_INTEL_MFX flag to the VideoCapture object, he fails the cap.isOpened() check and prints "Error openening video stream". (As defined in the code from https://www.learnopencv.com/read-write-and-display-a-video-using-opencv-cpp-python/.)

VideoCapture cap("video.264"); // works! VideoCapture cap("video.264", CAP_INTEL_MFX); // fails!

Now I'm a bit confused, since encoding seems to work fine, but this fails and doesn't seem to be a problem with the file.

Did anything regarding the Media SDK integration change since that GH Wiki page was created? Or do you people habe any other ideas about what could go wrong here?

Thanks!