Convert video to MATLAB image sequence

I am trying to convert a video into a sequence of images, and in mathworks I saw code like this

Read and play the xylophone.mp4 movie file.

xyloObj = VideoReader('xylophone.mp4');

nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;

Pre-select the film structure.

mov(1:nFrames) = ...
    struct('cdata',zeros(vidHeight,vidWidth, 3,'uint8'),...
           'colormap',[]);

Read one frame at a time.

for k = 1 : nFrames
    mov(k).cdata = read(xyloObj,k);
end

while I try to use this code, it takes a very long time to compile it. Is there a way to read all frames without a loop so that I can do it faster?

+4
source share
1 answer

, , . , , RGB . , - RGB. , read, .

read , MATLAB , . , 10 , :

video = read(xyloObj, [1 10]);

video - 4- , - , - , - ( 3), - . , i th, :

frame = video(:,:,:,i);

, read , . , :

video = read(xyloObj);

xylophone.mp4 ( ) 141 , 13 . - Mac OS Yosemite 10.10.3 MATLAB R2013a 16 Intel Core i7 2.3 . , , 4D-.

, , , , - read . , , , 10 20 , , ... - :

for idx = 1 : 20 : nFrames
    if idx + 20 > nFrames
        endIndex = nFrames;
    else
        endIndex = idx + 20;
    end
    video = read(xyloObj, [idx endIndex-1]);

    %// Continue processing
end

, read - , 13 , . , , save MAT .

+2

All Articles