How to parallelize video file frames decoding using OpenMP?

asked 2017-10-13 12:49:18 -0500

jczaja gravatar image


I'm very fresh user of OpenCV, so forgive me please naive question:)

Problem I'm working on is to speedup video reading&decoding . So far I used cv::VideoCapture::read() . But I read in doc that read is a sequence of grab and retrieve. So I though I could execute number of grab calls and then using OpenMP I could decode previously grabbed frames. Something like that:

VideoCapture cap("<my video="" file="">");
#pragma omp parallel single no wait
while(NOT <end of="" video="" file="">)

  // clone/store somehow grabbed frame 
  #pragma omp task firstprivate(encoded_image)

It does not work. It seems that problem is that opencv does not allow to get to capture buffer and copy this encoded image to my omp task so decoding can be done in parallel.

Any advice how to make it working ?

edit retag flag offensive close merge delete


"It does not work" -- no wonder. where you are trying to use it, it's a sequential job only.

you cannot do that from opencv usercode, but had to dive into ffmpeg (or whatever you're using)

berak gravatar imageberak ( 2017-10-14 02:11:43 -0500 )edit

Ok, perhaps then I could make to VideoCapture objects reading the same file in parallel. It just both of them would be grabbing the frames , but they will decode diffrent sets of frames eg. First VideoCapture would grab first frame and decode it and second VideoCapture would grab first, second but decode only second. Would such a configuration run in parallel shown some performance boost over sequential reading and decoding frames ?

jczaja gravatar imagejczaja ( 2017-10-16 06:48:24 -0500 )edit

@jczaja, again, no. and you're missing a lot of things how it works.

again, you cannot do any meaningful parallelization with code, that runs sequential.

they all ave to wait on each other, simply. you cannot change that.

berak gravatar imageberak ( 2017-10-16 06:59:54 -0500 )edit

Thanks very much for answer. I will look into ffmpeg usage then to speedup frames loading/decoding.

jczaja gravatar imagejczaja ( 2017-10-16 08:06:48 -0500 )edit