Problems creating a video file in MATLAB

I am trying to create a movie by going through the frames in MATLAB.

Referring to the mathworks.com documentation at http://www.mathworks.com/help/techdoc/ref/movie.html , I managed to revitalize the plot. However, problems arise when I try to save a movie in an AVI file.

Both of the avifile and VideoWriter from https://stackoverflow.com/a/4126/904 led to the same errors.

Although the animation works fine, a saved movie consists of only one fixed frame, and from time to time the screen capture includes an overlay of my background web browser.

Thanks in advance.

Below is the code I used and the frame that was frozen on 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

+6
source share
6 answers

Try the following:

  f = figure(); Z = peaks; surf(Z); a = axes('Parent',f); axis(a,'tight'); set(a,'nextplot','replacechildren'); vid = VideoWriter('myPeaks2.avi'); vid.Quality = 100; vid.FrameRate = 15; open(vid); for k = 1:20 surf(a,sin(2*pi*k/20)*Z,Z) writeVideo(vid, getframe(f)); end close(vid); winopen('myPeaks2.avi') 

It contains explicit descriptors that use implicit instead. Many havocs are caused in Matlab because people tend to use implicit ones, such as "gcf", "gca", which should have been completely removed from the language, IMHO.

+3
source

I had this (well, closely related) problem today. This stackoverflow topic was one of the best search engine results, so I thought that I would provide future searchers with additional information.

I used the VideoWriter object and called frame=getframe(fig_handle) to save each frame in 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.

Change rendering to artists or zbuffer. ( set(gcf,'renderer','zbuffer') ..)

I needed OpenGL rendering because the film used transparency. The key to this work was to use

 opengl('software') 

This circumvented what was probably the problem when sending graphics to and from the graphics card (I don’t know exactly ... it worked, and I switched).

+8
source

This works great for me.

What if you tried to put drawnow in a loop after surf ? (This clears all events and updates the schedule).

Maybe this is your movie player or codecs? Could you try VLC / Windows Media Player / etc etc.?

+3
source

I managed to get it working by making the shape frames invisible, according to http://www.mathworks.com/support/tech-notes/1200/1204.html :

 aviobj=avifile('test.avi'); %creates AVI file, test.avi hf= figure('visible','off'); %turns visibility of figure off hax=axes; for k=1:10 image(k.*peaks,'parent',hax); %puts image in invisible axes set(gca,'Zlim',[-20 20]); aviobj=addframe(aviobj,hf); %adds frames to the AVI file end aviobj=close(aviobj); %closes the AVI file close(hf); %closes the handle to invisible figure 

At the end of the day, no compression was used, since I do not have Indeo5. Is it right to say that we can eliminate compression as a problem?

0
source

Have you tried changing the monitor settings to 16-bit color? http://www.mathworks.com/matlabcentral/newsreader/view_thread/257389

0
source

I also had the problem of storing only one frame. Change frame rate from:

 vid.FrameRate = round(0.2*fps/beatfreq); 

which was rated to 3, simply:

 vid.FrameRate = 10; 

I don’t understand why this matters, but it worked quickly after changing this.

EDIT: Turns out it's a VLC that can't handle very low frame rates. Windows Media Player played fine.

0
source

Source: https://habr.com/ru/post/904204/


All Articles