Effacer les filtres
Effacer les filtres

How to analyse video frames in parallel?

8 vues (au cours des 30 derniers jours)
Sam Duckerin
Sam Duckerin le 20 Avr 2017
Hello, I'm working on processing large video files frame-by-frame. The processing for each frame is independent of other frames and is also computationally intensive, so I figured parallel processing would be a great way to speed up my analysis. While I have taught myself the basics of using parallel loops, I'm having problems combining the specifics of parfor with VideoReader objects. In my mind I imagine the code running like this
video = VideoReader('video.mp4');
parfor ii = 1 : 90000
frame = read(video, ii);
...analysis on frame...
end
However this warns me against using read() because it will be removed in a future version, so the only alternative I know of is to use frameRead(). However frameRead uses the CurrentTime property of the VideoReader object, which increments itself (according to the fps) each time frameRead is called. This works fine for reading frames in a normal loop, but it makes parfor unhappy because each frame relies on increasing the CurrentTime according to the last. Is there a way to access independent frames in a parallel loop using readFrame or otherwise? I've tried to set the CurrentTime value in each loop by using the loop index and the frame rate like this:
video = VideoReader('video.mp4');
fps = video.FrameRate
results = cell(totalFrames, 1);
parfor ii = 1 : 900000
video.CurrentTime = ii/fps;
frame = readFrame(video);
results{ii} = customAnalysisFunction(frame)
end
In this example the parfor is underlined and this message is provided:
MATLAB runs loops in parfor functions by dividing the loop iterations into groups,
and then sending them to MATLAB workers where they run in parallel. For MATLAB to do
this in a repeatable, reliable manner, it must be able to classify all the variables
used in the loop. The code uses the indicated variable in a way that is incompatible
with classification
What steps can I take to be able to read video frames in parallel that is compatible?

Réponses (1)

Megha Parthasarathy
Megha Parthasarathy le 25 Avr 2017
Hello,

Community Treasure Hunt

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

Start Hunting!

Translated by