nglview.contrib.movie¶
Module contents¶
-
class
nglview.contrib.movie.
MovieMaker
(view, download_folder=None, prefix='movie', output='my_movie.gif', fps=8, start=0, stop=-1, step=1, skip_render=False, timeout=1.0, in_memory=False, perframe_hook=None, render_params=None, moviepy_params=None)[source]¶ Bases:
object
Unstable API
view : NGLWidget download_folder : str or None
Folder that stores images. You can not arbitarily set this folder. It must be the download directory of the web browser you are using. If None, $HOME/Downloads/ will be used.- prefix : str, default ‘movie’
- prefix name of rendered image.
- output : str, default ‘my_movie.gif’
- output filename of the movie. if output has ‘.gif’, call write_gif, otherwise calling write_videofile
- fps : 8
- frame per second
- start, stop, step : int, default (0, -1, 1)
- how many frames you want to render.
- skip_render : bool, default False
- if True, do not render any frame and uses existings images in download_folder for movie making. if False, perform rendering first.
- timeout : a number (second), default 1.
- The waiting time between rendering two consecutive frames. You need to decide the “good” value by your self. timeout should be larger than the rendering time of each frame.
- render_params : dict or None, default None
- NGL rendering params. see NGLWidget.download_image. If None, use default values
- moviepy_params : dict or None, default None
- moviepy params for write_gif method. if None, use default values
- in_memory : bool, default False
- if False, save rendered images to disk first if True, keep all image data in memory (good for small video)
- perframe_hook : callable with view as a single argument, default None
- if given, update the view by perframe_hook.
>>> import nglview as nv >>> import pytraj as pt >>> traj = pt.load(nv.datafiles.XTC, top=nv.datafiles.PDB) >>> view = nv.show_pytraj(traj) >>> from nglview.contrib.movie import MovieMaker >>> download_folder = '/Users/xxx/Downloads' >>> output = 'my.gif' >>> mov = MovieMaker(view, download_folder=download_folder, output=output) >>> mov.make()
>>> # write avi format >>> from nglview.contrib.movie import MovieMaker
>>> moviepy_params = { ... 'codec': 'mpeg4' ... } >>> movie = MovieMaker(view, output='my.avi', in_memory=True, moviepy_params=moviepy_params) >>> movie.make()
unstable API. Currently supports .gif format If you are using remote notebook, make sure to set in_memory=True
moviepy. e.g:
pip install moviepy conda install freeimage