Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

animation - Problems with movie file creation in MATLAB

I attempt to create a movie by looping through frames in MATLAB.

Refering to mathworks.com documentation at http://www.mathworks.com/help/techdoc/ref/movie.html, I've managed to animate a plot. However, issues arise when I attempt to save the movie in an avi file.

Both the avifile and VideoWriter methods from https://stackoverflow.com/a/8038540/818608, resulted in the same errors.

Although the animation runs fine, the saved movie consists of only one fixed frame, and at times, the screen capture includes an overlay of my background web browser.

Thank you in advance.

Below is the code I used, and the frame that's frozen on the avi is linked below.

Z = peaks; surf(Z); 
axis tight
set(gca,'nextplot','replacechildren');

vid = VideoWriter('myPeaks2.avi');
vid.Quality = 100;
vid.FrameRate = 15;
open(vid);
for k = 1:20 
    surf(sin(2*pi*k/20)*Z,Z)
    writeVideo(vid, getframe(gcf));
end
close(vid);

winopen('myPeaks2.avi')

The frame that's frozen on the avi is linked below

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had this (well, a closely related) problem today. This stackoverflow topic was one of the top search engine results, so I thought I'd provide future searchers with some further info.

I was using a VideoWriter object, and calling frame=getframe(fig_handle) to save each frame to the video. As in the question to this topic, only 1 frame was saved. In addition, the background behind the figure could be seen through it, as if the figure was partially transparent.

Changing renders to painters or zbuffer worked. (set(gcf,'renderer','zbuffer') for example.)

I needed openGL rendering though, since the movie used transparency. The key to making this work was to use

opengl('software')

This circumvented what was probably an issue with sending the graphics to and from the video card (I don't know for sure... it worked, and I moved on).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...