MATLAB Answers

How to extract frames from a .mp4 video?

8 views (last 30 days)
Anthony Andrews
Anthony Andrews on 30 Nov 2019
Edited: Stephan on 1 Dec 2019
Hi I am trying to combine two videos in matlab. The first video is a clock moving with a green background. The second video is a black video moving in what it looks like is space. I am trying to extract the frames and make the second video the background to the first video. Using the code below only extracts the first frame, how can i extract all frames?
outputFolder1=('video');
v1=VideoReader('Clock.mp4');
vid1Frames=readFrame(v1);
for frame=1:size(vid1Frames,4)
outputBaseFileName=sprintf('%3.3d.png',frame);
outputFullFileName=fullfile(outputFolder1,outputBaseFileName);
imwrite(vid1Frames(:,:,:,frame),outputFullFileName,'png');
end

  0 Comments

Sign in to comment.

Answers (1)

Stephan
Stephan on 1 Dec 2019
Edited: Stephan on 1 Dec 2019
outputFolder1=('video');
v1=VideoReader('Clock.mp4');
vid1Frames=read(v1);
for frame=1:size(vid1Frames,4)
outputBaseFileName=sprintf('%3.3d.png',frame);
outputFullFileName=fullfile(outputFolder1,outputBaseFileName);
imwrite(vid1Frames(:,:,:,frame),outputFullFileName,'png');
end

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags