3
votes

Running Matlab R2011b under Linux, I am generating a video using the VideoWriter. My code goes something like this:

h_fig = figure();
set(h_fig, 'Visible', 'on')
set(h_fig, 'Position', [300,200,898,720]);
h_axs = axes('Parent', h_fig);
set(h_axs,'nextplot','replacechildren');
vidObj = VideoWriter('leadfollow3.avi');
...
for i = 1:n
    h_axs_a = subplot(3,2,[1 2]);
    plot(h_axs_a, x, a_mag_lead, x, a_mag_follow, 'r');
    ...

The plot is composed of several subplots. The first subplot renders fine, but for the rest, the axes background remains grey instead of white. What's worse, for certain frames it switches to white, leading to annoying flicker in the video (see example video here). Individual plots outside the video writer loop don't display this artifact. What might be the best strategy to troubleshoot this?

Edit: after I got a chance to try this code on Windows, it seems that the problem is restricted to Linux. Nonetheless, I would still very much like to know a possible solution, since I do not have regular access to Windows boxes where I could do my computations.

1
On linux, I prefer to export each frame as png and compress using ffmpeg.Memming
This seems to be a common theme... I tried this approach briefly and it was kind of slow and resulted in an incorrect framerate; I'll have to try it again, I suppose.Leo Alekseyev
I prefer to save as jpge, and create an mjpeg using the comical command cat *.jpg > out.mjpeg - Then you can use ffmpeg to convert it to what you want. Same story as @Memming, but I had better luck with ffmpeg starting with the mjpeg than trying to pass it crazy arguments.alexplanation
+1 for @Memming 's suggestion. I've also spent some time exporting video from Matlab, and the easiest solution in the end was to export individual frames and create the video with another program. (Quicktime in my case.) Also, nice dancing!DGrady

1 Answers

0
votes

You missed the crucial lines of code where you actually turn the figure into an image and send it to the VideoWriter, so it's difficult to be of much help. However, if you're not doing so already, I suggest you use export_fig for this task.