%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function 'avi2BMPFrames' takes input an UNCOMPRESSED .avi movie file and extracts frames from it in the form of rgb true-color
% bmp images which are stored with name prefixed as "framedump_0000X" where 'X' is the number of that particular frame in the order of
% its appearance.
%
% Programmer : Nilesh Ghubade (nileshg@temple.edu)
% Date : Sept 2002
% Advisor : Dr.Longin Jan Latecki (latecki@temple.edu )
% Project : Video Analysis (extracting key frames from a given movie file)
% Department : Computer and Information Science Department, Temple University, Philadelphia, PA-19122, USA
%
% Input arguments:-
% aviFileName = name of the UNCOMPRESSED .avi movie file.
%
% Output : -
% noOfFrameImages = The number of bmp frame images constructed from the input .avi file.
%       This function creates a set of frames from the .avi file in the form of rgb true-color bmp images which are stored with 
%       name prefixed as "framedump_0000X" where 'X' is the number of that particular frame in the order of its appearance.
%
% Example : avi2BMPFrames('movie.avi')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [noOfFrameImages] = avi2BMPFrames(aviFileName)
movieObj = aviread(aviFileName);
noOfFrameImages = size(movieObj,2);


for count=1:1:noOfFrameImages
    if ((1 <= count) & (count <= 9))
         imageFileNamePrefix = 'framedump_0000';
    else if ((10 <= count) & (count <= 99))
             imageFileNamePrefix = 'framedump_000';
        else imageFileNamePrefix = 'framedump_00'; 
        end
    end
    
    
    fileName = strcat(imageFileNamePrefix,num2str(count),'.bmp');
    imwrite(movieObj(count).cdata,fileName,'bmp');    
end
return;