写入流数据失败,matlab

发布于 2024-09-14 18:52:57 字数 1309 浏览 9 评论 0原文

我编写了一个将一组 BMP 转换为 avi 的脚本。直到最近它还运行良好。现在我收到这个奇怪的错误“无法写入流数据”。我将 5 个 bmp 库转换为 avi 后得到它。它运行 BMP 库并将每个库转换为 avi。每次它堆叠在第六部电影中时..第六个库中没有损坏的文件。知道为什么吗?

这是代码:

%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     

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     

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阳光的暖冬 2024-09-21 18:52:57

嗨,我知道这似乎有点过于简化,但我也遇到了同样的问题。
我的代码运行良好,只有一天就完全按照您所描述的那样停止了。我发现这只是我写入文件的目的地没有足够的内存来存储视频文件。删除了一些我不需要的垃圾,它立即起作用了。 Matlab 只是没有意识到问题出在存储空间上,所以在我的例子中,它说它自己的“movie2avi”函数存在问题

Hi I know this might seem a bit over simplified but I had the same issue.
My code worked fine and just one day stopped exactly as you have described. I found that it was just the destination I was writing my files to simply did not have enough memory for the video files. Deleted some junk I didn't need and it worked instantly. Matlab just doesn't realise the issue is with storage space so in my case it said there was an issue with its own 'movie2avi' function

黑色毁心梦 2024-09-21 18:52:57

由于我不确定问题的根源是什么,我只是提供一个如何创建 AVI 电影的简单工作示例。使用图像处理工具箱中的演示图像:

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

out.avi

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

out.avi

冷情妓 2024-09-21 18:52:57

库的顺序重要吗?换句话说,如果你先运行第 6 个,最后运行第 1 个,它会在第一个还是最后一个崩溃?

如果它第一次崩溃,那么你的库 #6 有问题
如果最后崩溃了,你可能在某个地方填满了内存。在运行脚本之前使用清除类,这应该消除 Matlab 填充在内存中的任何内容。或者,如果泄漏或碎片确实很严重,您可以尝试在三个库之后重新启动 Matlab。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文