# Making a movie with specific frame-rate out of ListPlot outputs? [duplicate]

I would like to make a movie that shows a series of Plot/ListPlot outputs as frames for s seconds of time each. Is there a simple way to do this?

-

## marked as duplicate by Jens, Sjoerd C. de Vries, whuber, rcollyer, R. M.♦Jan 11 '13 at 17:50

You might like to check out Animate and ListAnimate. – image_doctor Jan 11 '13 at 2:25
@image_doctor How would I output something like an AVI? – Roger Harris Jan 11 '13 at 2:37
Is really somewhere explained how to create an AVI where every frame stays e.g. 3 seconds on screen?? – halirutan Jan 11 '13 at 4:28
@halirutan To answer your question: Another closely related Q/A is this: Does Mathematica support variable frame rate for any video format, in analogue of GIF-style “DisplayDurations”? – Jens Jan 11 '13 at 5:56

When you have 50 frames already computed with Plot

expr = (1 - a) Exp[-x^2] + .5 a D[Exp[-x^2], x, x];
frames = Table[Plot[expr, {x, -2, 2}, PlotRange -> {Automatic, {-1, 1}},
Filling -> Bottom], {a, 0, 1, 1/49}];


what you can do when exporting e.g. "AVI" files is setting the "FrameRate". When you want to have for instance every frame displayed for 1 second the frame rate is 1 frame/second too. Unfortunately, this does only work for integer values and to have an image displayed for s seconds, you would have to set frame rate to 1/s. One bad hack is to set the frame rate to 1 and use several copies of the same frame. A better option here might be to use external tools. See for instance the link Jens gave in the comments

A different thing is, when you use animated "GIF" files. There you can set the "Duration" of every frame which can be larger than one second and smaller too.

Export["movie.gif", frames, "DisplayDurations" -> 1]


-
You've got a typo: it's FrameDurations, not FrameDuration. Without the s at the end, your exported movie doesn't actually have the duration you specified, but instead uses the default. – Jens Jan 11 '13 at 6:49
@Jens Thanks, I corrected my type (without using your Typo ;-) and now it works as expected. – halirutan Jan 11 '13 at 7:33
Wow, it this a type of typo explosion? – Jens Jan 11 '13 at 7:36

I might as well add another answer based on the variable frame rate GIF player contained in this answer:

exportMovie[movieName_String, list_, delayList_: {.03}] :=
Module[{l = Length[list],
delays = Abs@Flatten[{delayList}],
times,
totalTime,
delta,
frames},
delta = Min[delays];
times = Round[PadRight[delays, l, delays]/delta];
frames =
Flatten@Table[Table[list[[i]], {times[[i]]}], {i, Length[times]}];
Export[movieName, frames, "FrameRate" -> Round[1/delta]]
]


This takes a list of frames, e.g. the ones in halirutan's answer, and exports them as a movie in AVI or MOV or similar formats. These formats recognize the "FrameRate" option in Export, and you can calculate the desired frame rate as the reciprocal of the frame duration in seconds.

In this function, I generalized this to a variable frame rate by allowing an optional third argument that contains a list of individual frame durations. If the list is shorter than the number of frames, it's repeated. To make certain frames in the list of the first argument appear longer, I simply replicate them a number of times depending on how much longer than the minimum duration in the list of the third argument is.

So with the example

expr = (1 - a) Exp[-x^2] + .5 a D[Exp[-x^2], x, x];
frames = Table[
Plot[expr, {x, -2, 2}, PlotRange -> {Automatic, {-1, 1}},
Filling -> Bottom], {a, 0, 1, 1/49}];


you would simply do

exportMovie["a.mov", frames, {.12}]


to get a movie where all frames have an approximate duration of .12 seconds (there is rounding error).

The export format above is determined simply by the file name extension, so you could replace .mov by .avi.

-