Why does AVIFILE fail with the error "??? Failed to create video stream." ?

3 次查看(过去 30 天)
I have code that generates a movie using the AVIFILE function. The figures show up correctly but the AVI-file is never created.
The AVIFILE function fails with the following error:
??? Failed to create video stream.
Error in ==> avifile.addframe at 226
avi('addframe',rot90(frame,-1), aviobj.Bitmapheader, ...

采纳的回答

MathWorks Support Team
The issue is related to the fact that the AVI object itself never contains any frames. If the AVI object is updated in a subfunction (for example, 'makemovie' in the following code) and the subfunction does not return the updated AVI object to the main routine (for example, 'MainFcn' in the following code), a call to close(aviobj) in the main routine fails since the AVI object contains no data. This will cause the error listed above.
To work around this issue, ensure that when you close the AVI object, it contains at least one frame of data. In this case, the subfunction must always return the updated AVI object to the main routine.
The ideal way to create the movie in a subfunction is as follows:
function MainFcn
%create the AVI object here
aviobj = avifile('example.avi')
% function call to create the movie
aviobj = makemovie(aviobj);
% close the file
aviobj = close(aviobj);
return
function aviobj = makemovie(aviobj)
for i = 1:10
plot(1:10);
aviobj = addframe(aviobj, getframe(gcf));
end
return

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R14SP1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by