Skip to content

Commit 79beb15

Browse files
authored
Merge pull request #155 from christianbrodbeck/imageio
WIP: adapt Brain.save_movie() API for imageio
2 parents 89056ab + 756a9a6 commit 79beb15

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

surfer/viz.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,10 +2161,16 @@ def save_montage(self, filename, order=['lat', 'ven', 'med'],
21612161
return out
21622162

21632163
def save_movie(self, fname, time_dilation=4., tmin=None, tmax=None,
2164-
framerate=24, interpolation='quadratic', codec='mpeg4',
2165-
bitrate='1M'):
2164+
framerate=24, interpolation='quadratic', codec=None,
2165+
bitrate=None, **kwargs):
21662166
"""Save a movie (for data with a time axis)
21672167
2168+
The movie is created through the :mod:`imageio` module. The format is
2169+
determined by the extension, and additional options can be specified
2170+
through keyword arguments that depend on the format. For available
2171+
formats and corresponding parameters see the imageio documentation:
2172+
http://imageio.readthedocs.io/en/latest/formats.html#multiple-images
2173+
21682174
.. Warning::
21692175
This method assumes that time is specified in seconds when adding
21702176
data. If time is specified in milliseconds this will result in
@@ -2173,7 +2179,9 @@ def save_movie(self, fname, time_dilation=4., tmin=None, tmax=None,
21732179
Parameters
21742180
----------
21752181
fname : str
2176-
Path at which to save the movie.
2182+
Path at which to save the movie. The extension determines the
2183+
format (e.g., `'*.mov'`, `'*.gif'`, ...; see the :mod:`imageio`
2184+
documenttion for available formats).
21772185
time_dilation : float
21782186
Factor by which to stretch time (default 4). For example, an epoch
21792187
from -100 to 600 ms lasts 700 ms. With ``time_dilation=4`` this
@@ -2188,11 +2196,8 @@ def save_movie(self, fname, time_dilation=4., tmin=None, tmax=None,
21882196
Interpolation method (``scipy.interpolate.interp1d`` parameter,
21892197
one of 'linear' | 'nearest' | 'zero' | 'slinear' | 'quadratic' |
21902198
'cubic', default 'quadratic').
2191-
codec : str
2192-
Codec to use with ffmpeg (default 'mpeg4').
2193-
bitrate : str | float
2194-
Bitrate to use to encode movie. Can be specified as number (e.g.
2195-
64000) or string (e.g. '64k'). Default value is 1M
2199+
**kwargs :
2200+
Specify additional options for :mod:`imageio`.
21962201
21972202
Notes
21982203
-----
@@ -2211,6 +2216,15 @@ def save_movie(self, fname, time_dilation=4., tmin=None, tmax=None,
22112216
"run\n\n $ pip install -U "
22122217
"pysurfer[save_movie]\n")
22132218

2219+
# find imageio FFMPEG parameters
2220+
if 'fps' not in kwargs:
2221+
kwargs['fps'] = framerate
2222+
if codec is not None:
2223+
kwargs['codec'] = codec
2224+
if bitrate is not None:
2225+
kwargs['bitrate'] = bitrate
2226+
2227+
# find tmin
22142228
if tmin is None:
22152229
tmin = self._times[0]
22162230
elif tmin < self._times[0]:
@@ -2238,8 +2252,7 @@ def save_movie(self, fname, time_dilation=4., tmin=None, tmax=None,
22382252
% (times, time_idx))
22392253
images = (self.screenshot() for _ in
22402254
self._iter_time(time_idx, interpolation))
2241-
imageio.mimwrite(fname, images, fps=framerate, codec=codec,
2242-
bitrate=bitrate)
2255+
imageio.mimwrite(fname, images, **kwargs)
22432256

22442257
def animate(self, views, n_steps=180., fname=None, use_cache=False,
22452258
row=-1, col=-1):

0 commit comments

Comments
 (0)