Making a time-lapse video can also be as simple as skipping several frames from a video, to keep only the number of frames per second that will achieve the desired effect. Let's see how we can achieve this.
Our first step will be to use
VideoReader
to import a 2-minute driving video calledcar2min.avi
into MATLAB:>> E=VideoReader('car2min.avi');
Then, we will loop through our video using a large step (12 frames) and save the frames we visit into a new matrix:
>> k = 1; % This will be used as a counter for the frames we keep >> for i = 1:12:E.NumberOfFrames % Visit every 12th frame v(:,:,:,k)=read(E,i); % Save the frame in the kth position of v k=k+1; % Increase the counter by 1 end
At this point, we have our video, comprising 104 frames, saved in matrix
v
. We can now inspect it usingmontage
:>> montage(v,'Size',[7 15])
The result will be as follows:
Now we can save our time-lapse in a new video, using what we have...