Video to frames converting problem
Show older comments
I was using code to convert video into frames, i was working but now i am using video recorded by go pro hero 10 so the size of video is high , because of that now that code is not working . if i crop and trim video n reduces the size its working.
what should i do to convert high size video into images
% import the video file
video = VideoReader('test.mp4');
% read the total number of frames
n = video.NumberOfFrames
% reading and writing the frames
for i = 1:n
frames=read(video,i);
%save the frames
imwrite(frames,['images' int2str(i), '.jpg']);
im(i)=image(frames);
end
7 Comments
How exactly is it not working? Are you getting an error? If so, what is the error?
Since all I can do is guess, I'll just point out everything I see. I doubt that any of these are the cause of any error, but who knows.
% import the video file
video = VideoReader('test.mp4');
% read the total number of frames
%n = video.NumberOfFrames % this isn't recommended
n = video.NumFrames
% reading and writing the frames
for i = 1:n
frames = read(video,i);
%save the frames
%imwrite(frames,['images' int2str(i), '.jpg']); % these names won't sort easily
imwrite(frames,sprintf('images_%07d.jpg',i)); % these names will sort trivially
image(frames); % there's no point saving handles to deleted objects
end
Personally, I'd avoid the call to image(), since it's only going to slow the process and you're not going to see anything but the last frame anyway.
Manu Gowda
on 26 Jan 2022
DGM
on 26 Jan 2022
Interesting... So I guess read() is failing silently. Are the other properties of the video object populated correctly?
Walter Roberson
on 26 Jan 2022
Edited: Walter Roberson
on 26 Jan 2022
See
See also the documented limitation:
- For some AVI, MOV, or MP4 files on Windows®, using the readFrame function to read all of the frames in the file can result in a different number of frames than the value returned by the NumFrames property of the VideoReader object.
Manu Gowda
on 26 Jan 2022
"crop video below certain level" -- if you are referring to number of frames, then that would be consistent with the fact that NumberOfFrames and NumFrames are unreliable on Windows, and that the (now obsolete) NumberOfFrames was never known properly for variable framerate files until you finished reading the video.
Even for fixed framerate files, you need to take NumberOfFrames was an estimation, as recorded framerates are typically estimates. For example "30 frames per second" is typically NTSC, which is talked about as 29.97 frames per second but is really
format long g
30/1.001
and due to the way that frame rates are implemented as a ratio of two integers, round off typically occurs in the representation...
Manu Gowda
on 26 Jan 2022
Answers (0)
Categories
Find more on Video Formats and Interfaces in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!