Read frames from the mp4 file
Show older comments
filename = '01_original.mp4';
mov = VideoReader(filename);
opFolder = fullfile(cd, 'snaps');
if ~exist(opFolder, 'dir')
mkdir(opFolder);
end
numFrames =mov.NumberOfFrames;
numFramesWritten = 0;
for t = 1 : numFrames
currFrame = read(mov,t); %reading individual frames
opBaseFileName = sprintf('%3.3d.png', t);
opFullFileName = fullfile(opFolder, opBaseFileName);
imwrite(currFrame, opFullFileName, 'png');
progIndication = sprintf('Wrote frame %4d of %d.', t, numFrames);
disp(progIndication);
numFramesWritten = numFramesWritten + 1;
end %end of 'for' loop
progIndication = sprintf('Wrote %d frames to folder "%s"',numFramesWritten, opFolder);
disp(progIndication);
I just want to read frames from the mp4 file and try to storing in a snaps folder which im created.
it works fine for avi file. but when i reading the mp4 file i got the error
Error using imwrite (line 442)
Expected DATA to be nonempty.
Error in frames (line 13)
imwrite(currFrame, opFullFileName, 'png');
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!