% movietype = 0 qcif
% movietype = 1 sif
% movietype = 2 images
function Y = ReadVideo(filename, endframe, movietype)

GET_MOVIE=0;
PLAY_MOVIE=1;
Y=cell(1,endframe);
U=cell(1,endframe);
V=cell(1,endframe);
if (movietype==0)
    fid = fopen(filename,'r');
end
figure(1);
for i=1:endframe
    if (movietype==0)
        [Y{1,i},U{1,i},V{1,i}] = read_frame_qcif_new(fid,i);
    elseif (movietype==1)
        [Y{1,i},U{1,i},V{1,i}] = read_frame_sif(filename,i);
    end
    imagesc(Y{1,i});
    colormap(gray);
    if (GET_MOVIE)
        h=figure(1); 
        MM(:,i) = getframe(h);    
    end
end
if (movietype==0)
    fclose(fid);
end

if (GET_MOVIE&PLAY_MOVIE)
    figure(2);
    movie(MM,1,30);
end


