class_docstr: VideoRecorder renders a nice movie of a rollout, frame by frame.
  
  It comes with an ``enabled`` option, so you can still use the same code on episodes where you don't want to record video.
  
  Note:
      You are responsible for calling :meth:`close` on a created VideoRecorder, or else you may leak an encoder process.
class_docstr_tok: ["VideoRecorder","renders","a","nice","movie","of","a","rollout",",","frame","by","frame",".","It","comes","with","an","``","enabled","``","option",",","so","you","can","still","use","the","same","code","on","episodes","where","you","do","n't","want","to","record","video",".","Note",":","You","are","responsible","for","calling",":","meth",":","`","close","`","on","a","created","VideoRecorder",",","or","else","you","may","leak","an","encoder","process","."]
docstr: Flush all data to disk and close any open frame encoders.
docstr_tok: ["Flush","all","data","to","disk","and","close","any","open","frame","encoders","."]
code: def close(self):
      """Flush all data to disk and close any open frame encoders."""
      if not self.enabled or self._closed:
          return
  
      # First close the environment
      self.env.close()
  
      # Close the encoder
      if len(self.recorded_frames) > 0:
          try:
              from moviepy.video.io.ImageSequenceClip import (
                  ImageSequenceClip,
              )
          except ImportError:
              raise error.DependencyNotInstalled(
                  "MoviePy is not installed, run `pip install moviepy`"
              )
  
          logger.debug(f"Closing video encoder: path={self.path}")
          clip = ImageSequenceClip(
              self.recorded_frames, fps=self.frames_per_sec
          )
          clip.write_videofile(self.path)
      else:
          # No frames captured. Set metadata.
          if self.metadata is None:
              self.metadata = {}
          self.metadata["empty"] = True
  
      self.write_metadata()
  
      # Stop tracking this for autoclose
      self._closed = True
  
file_path: gym/gym/wrappers/monitoring/video_recorder.py
imports: import json
  import os
  import os.path
  import tempfile
  from typing import List, Optional
  from gym import error, logger
label_desc: Use image node_id 4 for calling the VideoRecorder obj's underlying member method code with example usage: obj.close() without return types