Time for action – time-lapsing a regular video

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.

  1. Our first step will be to use VideoReader to import a 2-minute driving video called car2min.avi into MATLAB:
    >> E=VideoReader('car2min.avi'),
  2. 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
  3. At this point, we have our video, comprising 104 frames, saved in matrix v. We can now inspect it using montage:
    >> montage(v,'Size',[7 15])
  4. The result will be as follows:
    Time for action – time-lapsing a regular video
  5. Now we can save our time-lapse in a new video, using what we have already learnt:
    >> lapse = VideoWriter('timelapse.avi'),
    >> lapse.FrameRate = 15;
    >> open(lapse);
    >> for i = 1:size(v,4)
    writeVideo(lapse,v(:,:,:,i));
    end
    close(lapse);
  6. If you want to preview your video, you can use implay:
    >> implay('timelapse.avi')

What just happened?

Congratulations! You have just made your first time-lapse video. Of course, it was a little less sophisticated than the average videos you might have seen in the documentaries, but nevertheless, it is a first step. You have achieved it by first importing a regular video and then selecting a large enough step to take sample frames from this video and save them in a new matrix. Finally, after inspecting all the frames of your newly constructed matrix using montage, you looped through all the frames to save them in a new video file with a frame rate of 15 fps. In the following chapters, we will get into the details of how to shoot the frames for a time-lapse using a photographic camera, a USB cable and a laptop with MATLAB.

Have a go hero – spinning our time-lapse

So, now that you know how to make a time-lapse, why not use another little trick to make it spin? You should try to rotate each frame by a fixed, arbitrary angle, and then save the result using the process you have already learned. If you do it correctly, the size of each frame will remain unaffected and you will have in your hands, a spinning timelapse video. Make sure that the angle you choose is not very small, or very large, so that the result is as smooth as possible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset