Is it possible to use parallel computing with VideoReader?

I am trying to read frames from a video in a parallel fashion, possibly using parfor. But parfor states that it cannot be used do to the nature of VideoReader. Any ways around this?

Respuestas (1)

Nathan, I am getting the following error:
Cannot call READ method after using READFRAME or HASFRAME methods or setting the CURRENTTIME property. Recreate the object to read a frame at a specific frame index.
when I execute:
vidObj = VideoReader('xylophone.mp4');
numFrames = vidObj.NumberOfFrames
parfor cnt = 1:numFrames
data = read(vidObj, cnt);
end
Are you getting the same error?
I think this is a bug that is addressed by the patch: Bug Report 1209823
Hope this helps.

6 comentarios

Actually, i believe my version of matlab does not support the read function anymore. it uses readFrame and the problem is that it reads frames starting at the 'currenttime' property. the issue with that is that if i put it in a parfor, id need to place the VideoReader(filename) object call inside the parfor which takes half a second per instantiation and that almost defeats the purpose of the parallel computing.
Any way of getting around this?
Nathan,
The read() function has not been removed. It continues to work. Starting in R2014b, MATLAB says that the read() function will be removed at a future time but as of 15a it works without any issues.
Dinesh
With 2014b on Mac OS X, the code above gives this error:
Error using VideoReader/read (line 134)
Cannot call READ method after using READFRAME or HASFRAME methods or setting the CURRENTTIME property. Recreate the object to read a frame at a specific frame index.
Nathan, are you trying to read in parallel different frames from the same video object? I would not expect that to work as the object has internal state about where it is positioned. Working with a copy of the object might potentially work, if the object defines a copy behaviour. Potentially relevant: http://www.mathworks.com/help/matlab/ref/matlab.mixin.copyable-class.html
Walter could you please give an example about how you might make a copy of a VideoReader object that would allow the frames to be read in parallel?
Hmmmm, it appears that VideoReader objects are handle class, and it appears that they do not have a copy semantics built in.
Ummm, it just might work to use https://www.mathworks.com/help/distcomp/parallel.pool.constant.html parallel.pool.Constant> from R2015b onwards
If you are doing a lot of reading from the same file, it might be worth using parfevalOnAll() to create the objects on each of the workers, which you would do once each time the file changed, rather than once for each parfor iteration.

Iniciar sesión para comentar.

Categorías

Más información sobre Parallel Computing Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 20 de Jul. de 2015

Comentada:

el 5 de Jul. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by