Total Pageviews


October 8, 2016

Video Processing and Creating Time Lapse Video...

by 4hathacker  |  in Image Processing at  3:44 PM

Hello everyone...!!!

In this article, I have discussed about video processing, saving video frames and time lapse video creation.

Time Lapse is an art of capturing video frames at a low frame rate than the actual frame rate of video capturing such that when these frames are combined and played back at a regular frame rate (say, 25fps), the viewer gets a sense that time is moving at a higher speed than normal. When the frames are captured using HD cameras, the results can be spectacular. You can see effects such as watching a flower bloom in seconds,  bean seeds germinating, etc.

The test video clip - test_suite.mp4 used in the article is taken from one of the hollywood science fiction blockbuster - Iron Man Series. He's the favorite super hero of my co-author also. The video depicts the dress up of Iron Man for combat. Its parameters include 29.97 frames per second, RGB 1280x720, with total 1402 frames available.

Using MATLAB, we first start reading a video saved at a location using VIDEOREADER created object. After that get a specific no. of for frame extraction. For example, I have used every 16th frame to be saved for time lapse video. Then, use VIDEOWRITER created object to save time lapse video. 

%%%%         Name: Nitin Sharma
%%%%         Code: timelapse.m
%%%%         MATLAB version: R2014a
%%%%         Toolbox Required: Image Processing Toolbox, Computer Vision 
%%%%                                        System Toolbox
%%%%          Utility: Selecting and saving frames from a video file, Creating 
%%%%                       time lapsed video, use the frames extracted to create 
%%%%                       gif file 

%%%                  VIDEOREADER object created with location of video
vid_read = VideoReader('C:\Users\ntnsh\Desktop\test_suite.mp4');
c = 1;                           %%%                      Counter for number of frames
%%%                  Slicing every 16th frame... If you want you can keep all the frames
%%%                  by leaving it
for l = 1:16:vid_read.NumberOfFrames 
 %%%                 read() from VIDEOREADER class to save frames
    v(:,:,:,c) = read(vid_read, l);  %%% read() from VIDEOREADER class to save frames
    c = c + 1;

%%% Saving each frame using file handling and imwrite... 
baseFileName = sprintf('suiteup_%d.jpg', c);
fullFileName = fullfile('E:\NewSuite', baseFileName);
imwrite(read(vid_read, l),fullFileName,'jpg');

%%%                        Showing Frame of Images in Montage Single Figure
montage(v,'Size',[12 10])

%%%                         Saving lapsed video
lapse = VideoWriter('timelapse.avi');                     %%% Creating VideoWriter Object
lapse.FrameRate = 22;                                           %%% Frame Rate for video 
for i = 1:size(v,4)                                                   %%% Writing frames in object
implay('timelapse.avi')                                          %%% Plays the time lapsed video

%%%                         Creating GIF File...
my_gif = 'GIF_LAPSE.gif'
for i = 1:size(v,4)
    [imind,cm] = rgb2ind(v(:,:,:,i),256);                 %%% rgb to indexed conversion
    if i==1

I also have done a .gif format creation of saved frames by converting them to indexed image at the end of the program. The number of frames saved is from 2nd to 88th. 

1 comment:

Like Our Facebook Page

Nitin Sharma's DEV Profile
Proudly Designed by 4hathacker.