class_docstr: Support for pyAV as backend.
  
  Parameters
  ----------
  request : iio.Request
      A request object that represents the users intent. It provides a
      standard interface to access various the various ImageResources and
      serves them to the plugin as a file object (or file). Check the docs for
      details.
class_docstr_tok: ["Support","for","pyAV","as","backend",".","Parameters","--","--","--","--","--","request",":","iio.Request","A","request","object","that","represents","the","users","intent",".","It","provides","a","standard","interface","to","access","various","the","various","ImageResources","and","serves","them","to","the","plugin","as","a","file","object","(","or","file",")",".","Check","the","docs","for","details","."]
docstr: 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.
  
  Parameters
  ----------
  ndimage : ArrayLike, List[ArrayLike]
      The ndimage to encode and write to the ImageResource.
  codec : str
      The codec to use when encoding frames. Only needed on first write
      and ignored on subsequent writes.
  is_batch : bool
      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.
  fps : str
      The resulting videos frames per second.
  in_pixel_format : str
      The pixel format of the incoming ndarray. Defaults to "rgb24" and can
      be any stridable pix_fmt supported by FFmpeg.
  out_pixel_format : str
      The pixel format to use while encoding frames. If None (default)
      use the codec's default.
  filter_sequence : List[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.
  
  Returns
  -------
  encoded_image : bytes 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.
  
  Notes
  -----
  When writing ``<bytes>``, the video is finalized immediately after the
  first write call and calling write multiple times to append frames is
  not possible.
docstr_tok: ["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",".","Parameters","--","--","--","--","--","ndimage",":","ArrayLike",",","List","[","ArrayLike","]","The","ndimage","to","encode","and","write","to","the","ImageResource",".","codec",":","str","The","codec","to","use","when","encoding","frames",".","Only","needed","on","first","write","and","ignored","on","subsequent","writes",".","is_batch",":","bool","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",".","fps",":","str","The","resulting","videos","frames","per","second",".","in_pixel_format",":","str","The","pixel","format","of","the","incoming","ndarray",".","Defaults","to","``","rgb24","''","and","can","be","any","stridable","pix_fmt","supported","by","FFmpeg",".","out_pixel_format",":","str","The","pixel","format","to","use","while","encoding","frames",".","If","None","(","default",")","use","the","codec","'s","default",".","filter_sequence",":","List","[","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",".","Returns","--","--","--","-","encoded_image",":","bytes","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",".","Notes","--","--","-","When","writing","``","<","bytes",">","``",",","the","video","is","finalized","immediately","after","the","first","write","call","and","calling","write","multiple","times","to","append","frames","is","not","possible","."]
code: def write(
      self,
      ndimage: Union[np.ndarray, List[np.ndarray]],
      *,
      codec: str = None,
      is_batch: bool = True,
      fps: int = 24,
      in_pixel_format: str = "rgb24",
      out_pixel_format: str = None,
      filter_sequence: List[Tuple[str, Union[str, dict]]] = None,
      filter_graph: Tuple[dict, List] = None,
  ) -> Optional[bytes]:
      """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.
  
      Parameters
      ----------
      ndimage : ArrayLike, List[ArrayLike]
          The ndimage to encode and write to the ImageResource.
      codec : str
          The codec to use when encoding frames. Only needed on first write
          and ignored on subsequent writes.
      is_batch : bool
          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.
      fps : str
          The resulting videos frames per second.
      in_pixel_format : str
          The pixel format of the incoming ndarray. Defaults to "rgb24" and can
          be any stridable pix_fmt supported by FFmpeg.
      out_pixel_format : str
          The pixel format to use while encoding frames. If None (default)
          use the codec's default.
      filter_sequence : List[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.
  
      Returns
      -------
      encoded_image : bytes 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.
  
      Notes
      -----
      When writing ``<bytes>``, the video is finalized immediately after the
      first write call and calling write multiple times to append frames is
      not possible.
  
      """
  
      if isinstance(ndimage, list):
          # frames shapes must agree for video
          if any(f.shape != ndimage[0].shape for f in ndimage):
              raise ValueError("All frames should have the same shape")
      elif not is_batch:
          ndimage = np.asarray(ndimage)[None, ...]
      else:
          ndimage = np.asarray(ndimage)
  
      if self._video_stream is None:
          self.init_video_stream(
              codec, fps=fps, pixel_format=out_pixel_format
          )
  
      self.set_video_filter(filter_sequence, filter_graph)
  
      for img in ndimage:
          self.write_frame(img, pixel_format=in_pixel_format)
  
      if self.request._uri_type == URI_BYTES:
          # bytes are immutuable, so we have to flush immediately
          # and can't support appending
          self._flush_writer()
          self._container.close()
  
          return self.request.get_file().getvalue()
  
imports: from fractions import Fraction
  from math import ceil
  from typing import Any, Dict, List, Optional, Tuple, Union, Generator
  import av
  import av.filter
  import numpy
  from numpy.lib.stride_tricks import as_strided
  from ..core import Request
  from ..core.request import URI_BYTES, InitializationError, IOMode
  from ..core.v3_plugin_api import ImageProperties, PluginV3
label_desc: Use image node_id 4 for calling the PyAVPlugin obj's underlying member method code with example usage: obj.write(ndimage) and returns: self