88
99import numpy as np
1010from matplotlib import animation
11- from matplotlib .animation import FFMpegWriter
11+ from matplotlib .animation import FFMpegWriter , ImageMagickWriter , PillowWriter , AVConvWriter
1212from .util import exec_no_show , listify_dict , extract_by_name
1313from ._version import schema_version
1414
@@ -74,7 +74,14 @@ def load_events(events):
7474
7575
7676def playback_file (
77- events , path , outputs , fps = 24 , from_first_event = True , prog_bar = True , ** kwargs
77+ events ,
78+ path ,
79+ outputs ,
80+ fps = 24 ,
81+ from_first_event = True ,
82+ prog_bar = True ,
83+ writer = "ffmpeg-pillow" ,
84+ ** kwargs ,
7885):
7986 """
8087 Parameters
@@ -95,8 +102,9 @@ def playback_file(
95102 prog_bar : bool, default: True
96103 Whether to display a progress bar. If tqdm is not
97104 available then this kwarg has no effect.
98- **kwargs :
99- Passed through to `FuncAnimation`.
105+ writer : str, default: 'ffmpeg-pillow'
106+ which writer to use. options 'ffmpeg', 'imagemagick', 'avconv', 'pillow'.
107+ If the chosen writer is not available pillow will be used as a fallback.
100108 """
101109 if isinstance (outputs , str ):
102110 outputs = [outputs ]
@@ -112,7 +120,7 @@ def playback_file(
112120 fps ,
113121 from_first_event ,
114122 prog_bar = prog_bar ,
115- ** kwargs
123+ writer = writers ** kwargs ,
116124 )
117125
118126
@@ -125,7 +133,8 @@ def playback_events(
125133 fps = 24 ,
126134 from_first_event = True ,
127135 prog_bar = True ,
128- ** kwargs
136+ writer = "ffmpeg-pillow" ,
137+ ** kwargs ,
129138):
130139 """
131140 plays back events that have been
@@ -148,6 +157,16 @@ def playback_events(
148157 accessors = {}
149158 fake_cursors = {}
150159 writers = []
160+ if writer == 'ffmpeg' and FFMpegWriter .isAvailable ():
161+ writer = FFMpegWriter
162+ elif writer == 'imagemagick' and ImageMagickWriter .isAvailable ():
163+ writer = ImageMagickWriter
164+ elif writer == 'avconv' and AVConvWriter .isAvailable ():
165+ writer = AVConvWriter
166+ else :
167+ writer = PillowWriter
168+
169+
151170 _figs = {} # the actual figure objects
152171 transforms = {}
153172 for fig , out in zip (figures , outputs ):
@@ -168,7 +187,7 @@ def playback_events(
168187 zorder = 99999 ,
169188 )[0 ]
170189 if outputs is not None :
171- writers .append (FFMpegWriter (fps , out ))
190+ writers .append (writer (fps ))
172191 writers [- 1 ].setup (_fig , out , len (events ))
173192
174193 times , mock_events = gen_mock_events (events , globals , accessors )
0 commit comments