Why does AVIFILE fail with the error "??? Failed to create video stream." ?
3 views (last 30 days)
Show older comments
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, ...
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
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 Comments
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!