mmread getting frames of video

1 visualización (últimos 30 días)
Ömer Faruk Kurular
Ömer Faruk Kurular el 31 de Oct. de 2019
Comentada: Turlough Hughes el 4 de Nov. de 2019
N = 3;
video = mmread('sample.avi', 10, [0 N]);
I = video.frames.cdata(:,:,:,1);
imshow(I);
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.

Respuestas (1)

Turlough Hughes
Turlough Hughes el 31 de Oct. de 2019
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)
N=3
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:
I=video.frames(indb(1)).cdata;
imshow(I)

Community Treasure Hunt

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

Start Hunting!

Translated by