写入流数据失败,matlab
我编写了一个将一组 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗨,我知道这似乎有点过于简化,但我也遇到了同样的问题。
我的代码运行良好,只有一天就完全按照您所描述的那样停止了。我发现这只是我写入文件的目的地没有足够的内存来存储视频文件。删除了一些我不需要的垃圾,它立即起作用了。 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
由于我不确定问题的根源是什么,我只是提供一个如何创建 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:
库的顺序重要吗?换句话说,如果你先运行第 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.