How to parallelize video file frames decoding using OpenMP?
Hi,
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="">) { cap.grab(); // clone/store somehow grabbed frame #pragma omp task firstprivate(encoded_image) { cap.retrieve(Image_to_write_to); } }
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 ?
"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)
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, 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.
Thanks very much for answer. I will look into ffmpeg usage then to speedup frames loading/decoding.