How do I save every nth Frame of a video and save these images to a folder of my choosing

12 views (last 30 days)
I have a video:
'Abuse001_x264.mp4'
I would like to extract every 10th frame from this video and save these as pictures in a folder called: Abuse_Images
How would I go about this?
  1 Comment
Jack Zimmerman
Jack Zimmerman on 15 Mar 2019
AbuseVid = VideoReader('Abuse047_x264.mp4')
numFrames = AbuseVid.NumberOfFrames;
n=numFrames;
for i = 1:10:n
frames = read(AbuseVid,i);
imwrite(frames,['C:\Users\John\MATLAB\Abuse\Abuse_Images\' int2str(i) '_47', '.jpg']);
end

Sign in to comment.

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 11 Mar 2019
If you follow the steps from the help on VideoReader, it should be perfectly possible to replace the frame-by-frame
reading described there to reading of whatever frames you desire - something like:
readerobj = VideoReader('Abuse001_264.mpg', 'tag', 'myreader1');
frames = [1 7 11 13 17 23 29];
for i1 = 1:numel(frames)
Frame = read(readerobj, frames(i1));
outname = sprintf('Outname-%03d.png',i1)
imwrite(Frame,outname)
end
I haven't tested this, but it should work, maybe you want to do more between extracting the frames and writnig them to file, but this should be a useful first step.
HTH

More Answers (0)

Community Treasure Hunt

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

Start Hunting!