def METHOD_NAME(self):
    """Flush all data to disk and close any open frame encoders."""
    if not self.enabled or self._closed:
        return
    # Close the encoder
    if len(self.recorded_frames) > 0:
        try:
            from moviepy.video.io.ImageSequenceClip import ImageSequenceClip
        except ImportError as e:
            raise error.DependencyNotInstalled(
                "moviepy is not installed, run `pip install moviepy`"
            ) from e
        clip = ImageSequenceClip(self.recorded_frames, fps=self.frames_per_sec)
        moviepy_logger = None if self.disable_logger else "bar"
        clip.write_videofile(self.path, logger=moviepy_logger)
    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