Search code examples
matlabvideo-processingparfor

Process video file in parallel


I'm trying to read a 25 second long video file in Matlab and trying to process it in parallel using parfor. I'm trying to split it into 5 shorter videos, each of 5 seconds length. Here is the code for that:-

mov = VideoReader('movie.avi');

parfor i=1:5

    vd(i)=read(mov,[(i-1)*5+1, (i)*5]);
    current_frame=0;
    while hasFrame(vd(i))
        current_frame=current_frame+1;            
        vidFrame = readFrame(vd(i));
        fprintf('%d part, frame no %d\n',i,current_frame);
    end
end

I keep getting this error on the first line inside parfor loop.

Subscripted assignment dimension mismatch

How do I retrieve what is coming from read function into the frame variable vd?


Solution

  • You are trying to store something that is not a scalar (read(mov, [start, stop])) into something that is a scalar (vd(i)). You likely want to make vd a cell array so that each element can hold something of an arbitrary size/dimension.

    vd{k} = read(mov, [(k-1)*5+1, (k)*5]);