Skip to content

Instantly share code, notes, and snippets.

@MichaelTr7
Last active March 30, 2021 01:34
Show Gist options
  • Save MichaelTr7/33620905943caa399c915fc5d976bc03 to your computer and use it in GitHub Desktop.
Save MichaelTr7/33620905943caa399c915fc5d976bc03 to your computer and use it in GitHub Desktop.
A MATLAB function to extract the frames from a video file.
function [Frame_Data,Video_Structure] = Grab_Video_Frames(File_Name)
Video_Properties = VideoReader(File_Name);
Video_Height = Video_Properties.Height;
Video_Width = Video_Properties.Width;
Number_Of_Frames = Video_Properties.NumFrames;
Colour_Channel_Matrix = zeros(Video_Height,Video_Width,3,'uint8');
Video_Structure = struct('cdata',Colour_Channel_Matrix,'colormap',[]);
Frame_Index = 1;
while(hasFrame(Video_Properties))
Video_Structure(Frame_Index).cdata = readFrame(Video_Properties);
Frame_Index = Frame_Index + 1;
end
Frame_Data = {Video_Structure.cdata};
end
File_Name = "Animated_Blocks_Test.avi";
[Frame_Data,Video_Structure] = Grab_Video_Frames(File_Name);
montage(Frame_Data, 'ThumbnailSize', [100 Inf]);
implay(Video_Structure);
@MichaelTr7
Copy link
Author

Output Results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment