I need to take 300 frames from the middle of a huge video (20000 frames) to do further manipulation. I got the following from the xylophone example but it only takes frames from the start of the video; I need to set a smaller video from frames 3701:4000:
Clip1 = VideoReader('C:\Users\(username)\Videos\Day3.4.avi'); %xylophone.mp4');
nFrames = 500; %Clip1.NumberOfFrames;
vidHeight = Clip1.Height;
vidWidth = Clip1.Width;
%%Movie Structure
mov(1:nFrames) = ...
struct('cdata',zeros(vidHeight,vidWidth, 3,'uint8'),...
'colormap',[]);
%%Reading frames
for k = 1 : nFrames
mov(k).cdata = read(Clip1,k);
end
hf = figure;
set(hf, 'position', [150 150 vidWidth vidHeight])
Any help would be greatly appriciated.

 채택된 답변

Geoff Hayes
Geoff Hayes 2014년 8월 20일
편집: Geoff Hayes 2014년 8월 21일

1 개 추천

Daevin - according to videoreader.read, it is possible to read in whichever frame that you wish
video = read(obj,index) reads only the specified frames. index can be a single number or a two-element array representing an index range of the video stream.
If you are interested only in the 300 frames starting at 3701, then your above code could be modified as
nFrames = 300; %Clip1.NumberOfFrames;
vidHeight = Clip1.Height;
vidWidth = Clip1.Width;
%%Movie Structure
mov(1:nFrames) = ...
struct('cdata',zeros(vidHeight,vidWidth, 3,'uint8'),'colormap',[]);
%%Reading frames
for k = 1:nFrames
mov(k).cdata = read(Clip1,3700+k);
end
Try the above and see what happens!
EDIT
Corrected the numFrames to nFrames as per Daevin's comment below.

댓글 수: 1

Daevin
Daevin 2014년 8월 21일
Fantastic. Of course its the last placement I didn't try. For anyone that uses this, change the numFrames to nFrames.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2014년 8월 19일

편집:

2014년 8월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by