I'm using the following code

Export["out.mov", Manipulate[Plot[Sin[2*Pi*k*x], {x, -1, 1},
PlotRange -> {{0, 1}, {-1, 1}}], {k, 0, 600, 0.001}], "FrameRate" -> 30]

to produce 600 plots of a sine function. If I set the FrameRate option to 30, I should have 600 frames at the rate of 30 frames per second, which gives me 20 seconds of animation time. Instead, I'm getting about 4 seconds and what is more, the animation runs twice (first time forward, and second time backwards).

How do I fix both of these problems?

  • 4
    $\begingroup$ For the speed of the video, this should help: mathematica.stackexchange.com/questions/5540/… $\endgroup$ – Jason B. Nov 10 '15 at 9:20
  • $\begingroup$ @JasonB, I don't understand the use of AutorunSequencing in that answer. $\endgroup$ – Physicsworks Nov 10 '15 at 9:22
  • $\begingroup$ You give the option {{1,10}} to AutorunSequencing, which tells it to run the first control element, k, over the course of 10 seconds. Still looking at how to not make it go forwards and backwards. Do you want to have the slider in the movie, I think it usually looks better without a slider $\endgroup$ – Jason B. Nov 10 '15 at 9:25
  • $\begingroup$ For what it's worth, I've always been of the opinion that the only good way to use Mathematica to create a movie file is to export frame images, and then combine them into a movie using ffmpeg or a similar program. The avi files, or mov files, Mathematica creates are subpar in every way. $\endgroup$ – Jason B. Nov 10 '15 at 9:26
  • $\begingroup$ @JasonB, Thanks, I understand now how to solve the first problem. I don't care about the slider as soon as I can put a caption saying the value of the changing parameter at any moment. And yeah, the thing that it runs backwards is just odd and inconvenient. Is there any way to cut it off once it finishes running forward? $\endgroup$ – Physicsworks Nov 10 '15 at 9:33

The documentation for AutorunSequencing says "Each variable always starts from the initial value specified for it, and returns to the same value," and doesn't give any indication that this behavior can be changed. So unless you absolutely want that slider in your animation, then exporting the results from Manipulate isn't a good way to make a movie file.

Create a list of images, here it has 600 images,

plotlist = 
  Table[Plot[Sin[2*Pi*k*x], {x, -1, 1}, 
    PlotRange -> {{0, 1}, {-1, 1}}, PlotPoints -> 100], {k, 0, 6, 

Then you can export the animation directly from Mathematica, using

Export["out.avi", plotlist, "Duration" -> 10, "FrameRate" -> 30]

(I'm using linux so I can't export a .mov file)

This creates a 20-second video file (why it is double the value given for duration, I don't know) that is 225MB.

A better option is to export frames and combine them into a movie using a better program.

  Export["frame_" <> IntegerString[n, 10, 4] <> ".png", 
  , {n, Length@plotlist}];
Run["! ffmpeg -framerate 30 -i frame_%04d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mov"]

The resulting animation file is also 20 seconds, and is only 280kB


Not the answer you're looking for? Browse other questions tagged or ask your own question.