Writing Video Frames in Parallel
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
So I came up with a way to write video frames in parallel so that I could take advantage of all the cores in my computer only I keep getting a weird bug where I can only write videos up to 52.1 MB. Does anyone have any idea what might be going on? Below is my code I've been using to write video frames in parallel.
spmd(1,4)
open(videoWriter);
CountIndex = [0];
for i = labindex:numlabs:numFiles
if labindex == 1
frame1 = imread(fullfile(workingDirectory, stackName, imageFiles(i).name));
end
if labindex == 2
frame2 = imread(fullfile(workingDirectory, stackName, imageFiles(i).name));
end
if labindex == 3
frame3 = imread(fullfile(workingDirectory, stackName, imageFiles(i).name));
end
if labindex == 4
frame4 = imread(fullfile(workingDirectory, stackName, imageFiles(i).name));
end
while ~any(abs(CountIndex-(labindex-1))<1e-10)
end
if labindex == 1
writeVideo(videoWriter,frame1);
end
if labindex == 2
writeVideo(videoWriter,frame2);
end
if labindex == 3
writeVideo(videoWriter,frame3);
end
if labindex == 4
writeVideo(videoWriter,frame4);
end
CountIndex = [CountIndex labindex];
if length(CountIndex) == length(numlabs)+1
CountIndex = [0];
end
end
end
end
6 comentarios
Walter Roberson
el 30 de Mayo de 2017
You should not need that extra labSend / labReceive: the labReceive specifies which worker it is waiting to hear from and it cycles through the workers, so if (say) worker 3 has the data ready before worker #2, then the data from worker 3 will sit in the queue until the labReceive(3) is executed. If worker 3's data is not ready yet then labReceive(3) would wait for it.
The one thing I do not know, though, is what happens if you cue multiple items, whether a single labReceive will pick them all up.
Here is another way to avoid the labSend / labReceive that you added:
spmd
if labindex == numlabs
open(videoWriter);
for i = 1 : numFiles
frame = labReceive('any', i);
writeVideo(videoWriter, frame);
end
else
for i = labindex:numlabs-1:numFiles
frame = imread( imageFiles(i).name );
labSend(frame, numlabs, i);
end
end
end
p = parpool();
f(1:numFiles) = parallel.FevalFuture;
for i = 1 : numFiles
f(i) = parfeval(p, @imread, 1, imageFiles(i).name );
end
open(videoWriter);
for i = 1 : numFiles
frame = fetchOutputs(f(i));
writeVideo(frame);
end
delete(f);
Respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!