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