mmread getting frames of video

조회 수: 1(최근 30일)
Ömer Faruk Kurular
Ömer Faruk Kurular 2019년 10월 31일
댓글: Turlough Hughes 2019년 11월 4일
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.

답변(1개)

Turlough Hughes
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)
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)
  댓글 수: 1
Turlough Hughes
Turlough Hughes 2019년 11월 4일
Did this work for you?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by