我写了一个脚本,将一组BMP转换为avi。直到最近,它都运行得很好。现在我得到了这个奇怪的错误“写入流数据失败”。我在将5个bmps库转换为avi后得到了它。它运行在BMP的库上,并将每个库转换为avi。每次它堆叠在第六部电影中..第6个库中没有损坏的文件。知道为什么吗?
代码如下:
%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 发布于 2010-08-13 08:58:33
由于我不确定你的问题的来源是什么,我只是提供了一个如何创建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

发布于 2013-03-01 20:09:04
嗨,我知道这看起来有点过于简单化了,但我也有同样的问题。我的代码运行得很好,只有一天完全按照你所描述的那样停止了。我发现它只是我写入文件的目的地,没有足够的内存来存放视频文件。删除了一些我不需要的垃圾,它很快就起作用了。Matlab没有意识到问题出在存储空间上,所以在我的例子中,它说它自己的'movie2avi‘函数有问题。
发布于 2010-08-13 18:16:48
库的顺序重要吗?换句话说,如果你先运行6次,最后运行1次,它会在第一次还是最后一次崩溃?
如果它在第一次崩溃,那么你的库#6就有问题了,如果它在最后一次崩溃,你可能会填满内存。在运行脚本之前使用clear classes,这样可以消除内存中填满的所有Matlab值。或者,如果泄漏或碎片非常严重,您可以尝试在三个库之后重新启动Matlab。
https://stackoverflow.com/questions/3471526
复制相似问题