How to process video in parallel?

8 vues (au cours des 30 derniers jours)
Ilya Tcenov
Ilya Tcenov le 3 Août 2019
Commenté : Ilya Tcenov le 10 Août 2019
Hello.
I need to read a video file (N frames long), process each adjucent pair of frames (to calculate a single output frame), and write the result as a video file (N-1 frames long). Processing time is important to me, so I am trying to do this in parallel.
I can't use a gpuArray() to pass a variable that was created using VideoReader() to the gpu (I get an error). It seems pointless to pass a pair of frames to the gpu and gather the result, as the transition of data back and forth takes longer than the calculation itself. Is there another way of using the gpu in my case?
I can use multiple workers (CPU), but the problem is that I cant write the result of a processed pair as a frame (using writeVideo() ), before the previous frame was writen. I need to make the worker wait if the previous frame wasn't writen yet. What will be the correct way of doing so?
Thank you.
  2 commentaires
Divya Gaddipati
Divya Gaddipati le 6 Août 2019
Does your current output frame depend on the previous output frame?
Ilya Tcenov
Ilya Tcenov le 10 Août 2019
Modifié(e) : Ilya Tcenov le 10 Août 2019
It doesn't.
Output(n) = function(Input(n),Input(n+1))

Connectez-vous pour commenter.

Réponse acceptée

Divya Gaddipati
Divya Gaddipati le 8 Août 2019
One possible approach is by using spmd. You could define spmd in such a way that each worker will operate on a chunk of the input video, and then within spmd it is possible to force each worker to write the resultant data in the specified order. Something like this:
spmd
    myFrameIdxs = find(discretize(1:totalNumFrames, numlabs) == labindex);
% numlabs - Total number of workers operating in parallel on current job
    % read chunk of data
    myFrameData = readVideoData(videoFname, myFrameIdxs);
    % process chunk of data
    myOutput = processVideoFrames(myFrameData);
    % output chunks of data in sequence, one at a time.
    for writeIdx = 1:numlabs
        if labindex == writeIdx
            writeVideoData(outVideoFname, myOutput);
        end
    end
end
For more information on how to use these functions, refer to the following links:
  1 commentaire
Ilya Tcenov
Ilya Tcenov le 10 Août 2019
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by