PyAVPlugin.write(ndimage: Union[ndarray, List[ndarray]], *, codec: Optional[str] = None, is_batch: bool = True, fps: int = 24, in_pixel_format: str = 'rgb24', out_pixel_format: Optional[str] = None, filter_sequence: Optional[List[Tuple[str, Union[str, dict]]]] = None, filter_graph: Optional[Tuple[dict, List]] = None) Optional[bytes][source]#

Save a ndimage as a video.

Given a batch of frames (stacked along the first axis) or a list of frames, encode them and add the result to the ImageResource.

ndimageArrayLike, List[ArrayLike]

The ndimage to encode and write to the ImageResource.


The codec to use when encoding frames. Only needed on first write and ignored on subsequent writes.


If True (default), the ndimage is a batch of images, otherwise it is a single image. This parameter has no effect on lists of ndimages.


The resulting videos frames per second.


The pixel format of the incoming ndarray. Defaults to “rgb24” and can be any stridable pix_fmt supported by FFmpeg.


The pixel format to use while encoding frames. If None (default) use the codec’s default.

filter_sequenceList[str, str, dict]

If not None, apply the given sequence of FFmpeg filters to each ndimage. Check the (module-level) plugin docs for details and examples.

filter_graph(dict, List)

If not None, apply the given graph of FFmpeg filters to each ndimage. The graph is given as a tuple of two dicts. The first dict contains a (named) set of nodes, and the second dict contains a set of edges between nodes of the previous dict. Check the (module-level) plugin docs for details and examples.

encoded_imagebytes or None

If the chosen ImageResource is the special target "<bytes>" then write will return a byte string containing the encoded image data. Otherwise, it returns None.


When writing <bytes>, the video is finalized immediately after the first write call and calling write multiple times to append frames is not possible.