I am doing a project that requires video processing. The code i used for accessing video frames gives the following error: "Error using VideoReader/read (line 145) . The frame index requested is beyond the end of the file."

1 view (last 30 days)
The videos i read were 4 to 5 seconds long. The code worked well for some video, but for few the error "Error using VideoReader/read (line 145) . The frame index requested is beyond the end of the file" is displayed. This is the code i used for getting the frames.
filename = strcat('C:\Users\Radhika\Documents\MATLAB\SV_sample\Video\G_1_2.mp4');
mov = VideoReader(filename);
get(mov);
numFrames = mov.NumberOfFrames;
for t = 1 : numFrames
rgbFrame = read(mov, t ); %reading individual frames
end %end of 'for' loop

Accepted Answer

Image Analyst
Image Analyst on 20 Jun 2014
I don't see any reason off the top of my head. read() doesn't start with 0 instead of 1 does it? Otherwise, just wrap in try catch:
for t = 1 : numFrames
try
rgbFrame = read(mov, t ); %reading individual frames
catch
break; % Exit loop if beyond last frame.
end
end %end of 'for' loop
  5 Comments
Radhika
Radhika on 21 Jun 2014
Ok Sir, but why do i get numFrames for other videos??? All the videos i use are capture by same WebCamera and all video are of 4 or 5 seconds duration.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!