Parallel VideoReader Image processing

Hey,
I am trying to look at each frame inside a video and do some processing on it. Is there a way to do this in parallel? I am attempting to do the same thing to every 12th frame, and I assume it should be independent because each frame is independent of each other. However, I have come across issues with VideoReader and it's read function inside a parfor loop. Please point me to some resources if you know any! I have looked for ways to do this on the GPU as well, but I could't find much, so let me know if you know anything about that either. Thank you in advance!
-Tim

Answers (1)

If you were to open the object once and send the reader to the workers and ask them to read different frames, then that would be expected to have problems.
If you were to open the file in every worker then they would not interfere with each other. However using read() with an index is discouraged and will go away soon, and instead readFrame multiple times is the method for frame accurate extraction. The alternative is to set the CurrentTime field by time, which can present difficulties in getting an exact spacing between frames for variable framerate videos.
What I would suggest in your case is that you have a single loop that reads frames one by one with readFrame and throws away most of them but takes every 12th and parfeval() the processing work, which submits it to the queue for asynchronous processing. Eventually you collect the results. The number to leave outstanding uncollected depends on your available memory.

1 Comment

Hi Walter,
Thank you for a quick reply. Could you expand on what you mean by "The number to leave outstanding uncollected depends on your available memory"? I think you are saying that the memory may be an issue since whole frames are being passed to parfeval() and there may not be enough memory to collect all the outputs.
While I was working earlier, I thought of storing each frame in an intermediate array and then using a "parfor" on the intermediate array. How would this compare to your method? I am thinking that they both run into issues of memory (my method actually froze my computer after it ran out of memory), since there is some intermediate storing of the frames, but I am not too sure about the performance comparison. I would appreciate it if anyone else had resources that may relate to using the GPU to do this processing as well. Hope to hear from you again Walter. Thanks.
-Tim

Sign in to comment.

Asked:

on 9 Mar 2016

Commented:

on 9 Mar 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!