My Export is taking a very long time, I was hoping there might be a way to monitor the progress when exporting graphics?
AbsoluteTiming[Export["timeline.gif", table, ImageSize -> 1000]]
My Export is taking a very long time, I was hoping there might be a way to monitor the progress when exporting graphics?
AbsoluteTiming[Export["timeline.gif", table, ImageSize -> 1000]]
Mathematica's Export of animated GIFs isn't perfect. I personally prefer to Export only individual frames from Mathematica, and then use a third-party program for assembling them into an optimized animated GIF. In this case it is easy to monitor the process of Exporting of individual frames:
table = Table[
Plot[Sinc[t x], {x, 0, 10}, PlotRange -> 1], {t, 0, 10, .1}];
n = Length[table];
CreateDirectory["timeline.gif (frames)"]
PrintTemporary[ProgressIndicator[Dynamic[k], {1, n}]];
Do[Export[
"timeline.gif (frames)/frame_" <> IntegerString[k, 10, 4] <> ".gif",
table[[k]]], {k, n}]
Caveat: In the above code I Export frames into GIF for compatibility with free Gifsicle utility (see below) which can read only GIF. The drawback is that every frame has its own palette of colors which is limited for GIF to at most 256 colors. When these frames will be combined into one optimized animated GIF a new color palette (also limited to at most 256 colors) will be generated which will be common for all the frames. It is clear that this process should degrade the quality of most of the frames. In order to avoid this effect I recommend to Export frames into more rich image format like PNG or (even better) TIFF and then use a professional tool like GIF Movie Gear for assembling frames into one optimized GIF having the best possible quality with smallest possible size.
The following is an example (works under MS Windows but can be easily adapted for other OSs) of how the creation of the animated GIF can be automatized using the free Gifsicle utility (I intentionally do not close the console window for having an ability to see the messages generated):
wrapByQuotes[s_String] := "\"" <> s <> "\"";
pathToGifsicle = "D:\\PROGRAMS\\gifsicle\\gifsicle.exe";
framesPath = FileNameJoin[{Directory[], "timeline.gif (frames)", "*.gif"}];
outputFilePath = FileNameJoin[{Directory[], "timeline.gif"}];
command =
wrapByQuotes[
StringJoin[wrapByQuotes@pathToGifsicle,
" --delay=10 --loop --optimize=3 ",
wrapByQuotes@framesPath,
" --output ", wrapByQuotes@outputFilePath]];
Run["start cmd /K", command]
The result is a file of size 182 Kb (compare to 290 Kb size of file generated by Mathematica!):
P.S. Information on subtleties of using of the Run command can be found in this answer by Rui Liu (Wolfram Technical Support).
From the other side, the GIF Export time in Mathematica seems to be a linear function of the number of frames, so after some initial benchmarking it is possible to predict the approximate time needed for Exporting of a GIF with given number of frames:
table = Table[
Plot[Sinc[t x], {x, 0, 10}, PlotRange -> 1], {t, 0, 10, .1}];
nMax = 60;
First@AbsoluteTiming[
timings =
Table[First@
AbsoluteTiming[Export["timeline.gif", Take[table, k]]], {k, 1, nMax}];]
lm = LinearModelFit[timings, x, x];
Show[Plot[lm["Function"][n], {n, 1, nMax}], ListPlot[timings],
Frame -> True, Axes -> False,
Epilog -> Text[lm["Function"][N], ImageScaled[{.5, .9}]],
FrameLabel -> {"Number of frames N", "Time, seconds"}]
174.896
Export frames into GIF. Exporting into more rich image format is preferred in order to obtain the best optimized color palette which will be common for the all frames in the final animated GIF. So better solution would be to Export frames into PNG (or even TIFF) and then assemble them into animated GIF using a professional tool like imagemagick. I have very good experience with GIF Movie Gear.
– Alexey Popkov
Jun 10 '15 at 13:50
GIFexport speed truly is awful. – Yves Klett Jun 10 '15 at 06:30Exportto"VideoFrames"as I mention in this answer, and assemble the gif in an external tool such asImageMagickorGraphicsMagick, or evenffmpeg. Then you have the direct "progress indicator" in the form of the file listing in your directory (i.e., you can watch the directory filling up with the individual video frames as they are created). I won't write this as an answer because it's just an alternative toGIFexport... – Jens Jun 10 '15 at 16:08GIFexport, too. In particular, it helps to choose the image size and dimensions at the rasterizing stage, not in theGIFexport. – Jens Jun 10 '15 at 16:11