Converting images to avi file in matlab

Here is the matlab code to convert a collection of images to a video file.

%// Will open an avi file name test.avi in local folder
aviobj = avifile('test.avi');
%// the quality of this video file
aviobj.Quality = 80;
%// compression method. See matlab manual for details.
aviobj.COMPRESSION ='None';%%color image

for i =1:numOfFrames
    %// apply image processing algorithms to the image here. 
    %// image must be in size width x height x 3
    %//  in other words, color image. 
    %// add image to the end of the avi file
    aviobj = addframe(aviobj,image);
%// close the file handle.
aviobj = close(aviobj);

Click here for detail instruction on addframe function.

Keywords: convert images jpb bmp to video avi compressed codec

5 Responses to Converting images to avi file in matlab

  1. Junaid says:

    Great work!
    job done!
    I used your code to make the complete code to read files from the directory which is:
    %my file names started from 36.jpg to 70.jpg
    aviobj = avifile(‘flameDetected.avi’);
    aviobj.Quality = 80;
    aviobj.COMPRESSION =’None’;

    for i =36:70
    image= imread([int2str(i),’.jpg’]);
    aviobj = addframe(aviobj,image);

    aviobj = close(aviobj);

  2. Welcome to – Free GFX source for you…

    […]Converting images to avi file in matlab « Jason Yu-Tseh Chi’s Notes[…]…

  3. sunil kumar k says:

    b = 1;
    npic = 500;
    mov = avifile(‘MakeVi01.avi’)%MakeVi01.avi name of avi-file save to your comp.
    for i=b:npic;
    str = num2str(i);
    name = strcat(”,”,str,’.jpg’);% ex. image1.tiff : (file name= ‘SPT200’)
    MAT = imread(name);
    axis off;

    F(i) = getframe(gca);
    mov = addframe(mov,F(i));
    mov = close(mov)

    can convert avi file frame name 1 to 500

  4. felarenthlei says:

    Thanks for this code, and is exactly what I need.

    But, I have a problem which I want to request to be addressed :
    The animation works fine, but the magnitudes (text characters) and the colors are lost.
    How shall I fix this ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: