8000 DOC: re-work MovieWriter section a bit · matplotlib/matplotlib@55017cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 55017cd

Browse files
committed
DOC: re-work MovieWriter section a bit
1 parent ff1e71e commit 55017cd

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

doc/api/animation_api.rst

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,76 @@ Writer Classes
173173

174174

175175

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+
176181
.. autosummary::
177182
:toctree: _as_gen
178183
:nosignatures:
179184

180-
AVConvFileWriter
181-
AVConvWriter
182-
FFMpegFileWriter
185+
183186
FFMpegWriter
184187
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
185199
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+
186246

187247
:ref:`animation-moviewriter`
188248

0 commit comments

Comments
 (0)
0