tags:

views:

53

answers:

2

hi
I have writtring a script that convert a set of BMPs to avi. up until recently it worked fine. now I get this wierd error "Failed to write stream data". I get it after converting 5 libraries of bmps to avi. It runs over librarirs of BMPs and convert each library to avi. each time it stacks in the 6th movie.. there are no corrupts files in the 6th library. any idea why?

this is the code:

%this works   
clc   
%path='C:/Documents and Settings/Ariel/Desktop/exp_brk_scrm/2.1/group1/exp_up/exp_up/4python/stims';   
%FullPath=strcat(path,'/mov1.avi');   
path4avi='G:/experiments/cfs3/building/Copy of StimBMP/avi/'; %dont forget the   in the end of the path    
pathOfFrames='G:/experiments/cfs3/building/Copy of StimBMP/stims/'; %here too   
NumberOfFiles=70; %to be generated   
NumberOfFrames=8; %in each avi file    

for i=1:1:(NumberOfFiles)    

    FileName=strcat(path4avi,'Stim',int2str(i),'.avi') %the generated files    
    aviobj = avifile(FileName,'compression','None'); %due to changes in the new Media Players   
    aviobj.fps=10;%10 frames in Sec     

    for j=1:1:(NumberOfFrames)   

        Frame=strcat(pathOfFrames,'stim',int2str(i),'/stim',int2str(j),'.BMP') % the BMP's (not a good name for thedirectory)    

        %[Fa,map]=imread(Frame);     
        %imshow(Fa,map); %
        [Fa,map]=imread(Frame);
        imshow(Fa,map);       
        % imshow(Fa);     
        F=getframe();    
        aviobj=addframe(aviobj,F)    
    end     
    aviobj=close(aviobj);    

end     
+1  A: 

Since I'm not sure what the source of your problem is, I'm just providing a simple working example of how to create an AVI movie. Demo images from the Image Processing Toolbox are used:

figure('Color','white')
aviObj = avifile('out.avi', 'fps',5);             %# create AVI object
for i=1:10
    I = imread( sprintf('AT3_1m4_%02d.tif',i) );  %# read image frame
    imshow(I, 'Border','tight'), colormap gray    %# show image
    aviObj = addframe(aviObj, getframe(gcf));     %# grab frame and add to AVI
end
close(gcf)
aviObj = close(aviObj);                           %# close and write movie

winopen('out.avi')                                %# play movie in Windows

I've uploaded the resulting AVI movie.

snapshot

Amro
A: 

Does the order of the libraries matter? In other words, if you run the 6th first and the 1st last, will it crash on the first or on the last?

If it crashes on the first, then you library #6 has a problem If it crashes on the last, you may be filling up memory somehwere. Use clear classes before running your script, which should eliminate whatever Matlab is filling up in the memory. Alternatively, if the leak or fragmentation is really bad, you could try and restart Matlab after three libraries.

Jonas

related questions