@@ -173,16 +173,76 @@ Writer Classes
173
173
174
174
175
175
176
+ The provided writers fall into two broad categories: pipe-based and
177
+ file-based. The pipe-based writers stream the captured frames over a
178
+ pipe to an external process. The pipe-based variants tend to be more
179
+ performant, but may not work on all systems.
180
+
176
181
.. autosummary ::
177
182
:toctree: _as_gen
178
183
:nosignatures:
179
184
180
- AVConvFileWriter
181
- AVConvWriter
182
- FFMpegFileWriter
185
+
183
186
FFMpegWriter
184
187
ImageMagickFileWriter
188
+ AVConvWriter
189
+
190
+ Alternatively the file-based writers save temporary files for each
191
+ frame which are stitched into a single file at the end. Although
192
+ slower, these writers can be easier to debug.
193
+
194
+ .. autosummary ::
195
+ :toctree: _as_gen
196
+ :nosignatures:
197
+
198
+ FFMpegFileWriter
185
199
ImageMagickWriter
200
+ AVConvFileWriter
201
+
202
+
203
+ Fundamentally, a MovieWriter does is provide is a way to grab
204
+ sequential frames from the same underlying `~matplotlib.figure.Figure `
205
+ object. The base class `MovieWriter ` implements 3 methods and a
206
+ context manager. The only difference between the pipe-based and
207
+ file-based writers in the arguments to their respective ``setup ``
208
+ methods.
209
+
210
+
211
+ .. autosummary ::
212
+ :toctree: _as_gen
213
+ :nosignatures:
214
+
215
+ MovieWriter.setup
216
+ FileMovieWriter.setup
217
+ MovieWriter.grab_frame
218
+ MovieWriter.finish
219
+ MovieWriter.saving
220
+
221
+
222
+ The ``setup() `` method is used to prepare the writer (possibly opening
223
+ a pipe), successive calls to ``grab_frame() `` capture a single frame
224
+ at a time and ``finish() `` finalizes the movie and writes the output
225
+ file to disk. For example ::
226
+
227
+ moviewriter = MovieWriter(...)
228
+ moveiewriter.setup(fig=fig, 'my_movie.ext', dpi=100)
229
+ for j in range(n):
230
+ update_figure(n)
231
+ moviewriter.grab_frame()
232
+ moviewriter.finish()
233
+
234
+
235
+ If using the writer classes directly (not through `Animation.save `), it is strongly encouraged
236
+ to use the `~MovieWriter.saving ` context manager ::
237
+
238
+ with moviewriter.saving(fig, 'myfile.mp4', dpi=100):
239
+ for j in range(n):
240
+ update_figure(n)
241
+ moviewriter.grab_frame()
242
+
243
+
244
+ to ensures that setup and cleanup are performed as necessary.
245
+
186
246
187
247
:ref: `animation-moviewriter `
188
248
0 commit comments