Saving animations#
Render a clip once and derive every other format from the written file.
Drawing frames costs far more than encoding them, so save_animation encodes the animation to a video and —
when a GIF is also wanted — reads the frames back off that file rather than redrawing them. It also raises the
intermediate video to full chroma in that case, because a subsampled source permanently caps how much colour
detail can survive the GIF palette.
Reachable as Map.save_animation and TexturedGlobe.save_animation, or directly as the function below.
digitalearth.static.render.animation.save_animation(anim, path, *, fps=None, gif=None, gif_options=None, **kwargs)
#
Save anim to path, optionally deriving a GIF from the written file without re-rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anim
|
Any
|
The matplotlib |
required |
path
|
str | PathLike[str]
|
Output path. The extension picks the format — |
required |
fps
|
float | None
|
Frames per second. Defaults to :data: |
None
|
gif
|
str | PathLike[str] | None
|
When given, a second output path to derive a GIF at, by reading the frames back off |
None
|
gif_options
|
dict | None
|
Extra keyword arguments for |
None
|
**kwargs
|
Any
|
Forwarded to cleopatra's |
{}
|
Returns:
| Type | Description |
|---|---|
str | tuple[str, str]
|
The written path as a |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Warns:
| Type | Description |
|---|---|
RuntimeWarning
|
If |
Note
The rate is rounded to a whole number once, and the same value is used for the video and for the
derived GIF, so the two files play at the same speed unless gif_options deliberately overrides it.
Examples:
- Rendering once and delivering two formats, without drawing the frames twice:
Source code in src/digitalearth/static/render/animation.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |