Azzera filtri
Azzera filtri

How can we use 'SPMD' for 'VideoReader'?

2 visualizzazioni (ultimi 30 giorni)
MOHIT
MOHIT il 16 Giu 2016
Modificato: MOHIT il 17 Giu 2016
hi, I want to do do some video quality reduction fastly, I am using parallel computing , but this error is coming: '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'
my code is
videoSrc = VideoReader('rhinos.avi');
% v = VideoWriter('newfile.avi');
% open(v)
spmd
if labindex==1
v = VideoWriter('newfile.avi');
open(v)
for sr = 1:700
huo = read(videoSrc,sr);
RGB2 = imresize(huo, [300 NaN]);
writeVideo(v,RGB2)
% waitbar(sr / videoSrc.NumberOfFrames)
end
close(v)
else
R = rand(4,4);
end
end

Risposta accettata

Sean de Wolski
Sean de Wolski il 16 Giu 2016
Use readFrame() instead of read(). I'd also recommend building the videoSrc on the worker.
spmd
if labindex==1
videoSrc = VideoReader('rhinos.avi');
for ii = 1:700
if hasFrame(videoSrc)
huo = readFrame(videoSrc);
else
break
end
end
end
end

Più risposte (1)

Steven Lord
Steven Lord il 16 Giu 2016
Writing video to a file seems like an inherently serial operation since you care about the order in which the frames are written to the file. So I wouldn't try to parallelize this.
Picture watching Star Wars if the Death Star exploded first, then Princess Leia was rescued, then Luke and Obi-Wan met Han Solo in the cantina, then Luke was flying his X-Wing toward the Death Star trench. It doesn't really make sense out of order, does it?
  1 Commento
MOHIT
MOHIT il 17 Giu 2016
Modificato: MOHIT il 17 Giu 2016
hi, yes you are right, output video needs to be in a sequence and this is the reason I am using 'spmd' not 'parfor'. Because 'spmd' gives results in an organised way.
see this:
spmd
if labindex==1
dataToSend=1:10
elseif labindex==2
dataToSend=1:2:10
elseif labindex==3
dataToSend=1:3:10
elseif labindex==4
dataToSend=1:4:10
end
end

Accedi per commentare.

Categorie

Scopri di più su Parallel Computing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by