Skip to content

Instantly share code, notes, and snippets.

@sarchertech
Created September 28, 2012 01:45
Show Gist options
  • Save sarchertech/3797522 to your computer and use it in GitHub Desktop.
Save sarchertech/3797522 to your computer and use it in GitHub Desktop.
Matlab function, converts a movie to a folder of jpeg images
function [num_frames, folder_name] = video_to_frames( file_name )
% Author: Seth Brown 9/27/2012
% License: MIT License
% Store each frame of the video as a numbered jpeg image
% Use: [numFrames, folderName] = video_to_frames('sample.mp4');
% TODO Error handling--specifically on grabbing frames and file write
video = VideoReader(file_name);
num_frames = video.NumberOfFrames;
% Make folder to contain frame jpegs
folder_name = 'frames';
mkdir(folder_name);
% Read one frame at a time.
for k = 1:num_frames
frame = read(video, k);
str = sprintf('%s\\%d.jpg', folder_name, k);
imwrite(frame, str);
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment