mmread getting frames of video
조회 수: 3(최근 30일)
N = 3;
video = mmread('sample.avi', 10, [0 N]);
I = video.frames.cdata(:,:,:,1);
I need to open video and grab frames of it -frames in 0 to N seconds and 10 frame each second-. Above code gives just first frame of video and when I do the following, error thrown.
I = video.frames.cdata(:,:,:,2);
with the error "Index in position 4 exceeds array bounds (must not exceed 1)." How can I get frame array of first n seconds properly.
Turlough Hughes 2019년 10월 31일
To get your 10 frames each second from 0 to N seconds you can do the following (Note though that if you are converting from a standard such as 24 fps to 10 fps you will end up sampling frames 1, 3, 6, 8, 11, 13, 16, etc....the spacing is not consistent because 24/10 is not an integer value)
samples=10*N; % New FPS multiplied by overall time N = new number of frames
[~,inda]=min(abs(video.times-N)) % idx is frame closest too time N
indb=round(linspace(1,inda,samples)) % index for "evenly" spaced frames of original video
To show an individual frame it is just: