code: def ffmpeg_write_image(
      filename, image, logfile=False, pixel_format=None
  ):
      """Writes an image (HxWx3 or HxWx4 numpy array) to a file, using ffmpeg.
  
      Parameters
      ----------
  
      filename : str
          Path to the output file.
  
      image : np.ndarray
          Numpy array with the image data.
  
      logfile : bool, optional
          Writes the ffmpeg output inside a logging file (``True``) or not
          (``False``).
  
      pixel_format : str, optional
          Pixel format for ffmpeg. If not defined, it will be discovered checking
          if the image data contains an alpha channel (``"rgba"``) or not
          (``"rgb24"``).
      """
      if image.dtype != "uint8":
          image = image.astype("uint8")
      if not pixel_format:
          pixel_format = "rgba" if (image.shape[2] == 4) else "rgb24"
  
      cmd = [
          FFMPEG_BINARY,
          "-y",
          "-s",
          "%dx%d" % (image.shape[:2][::-1]),
          "-f",
          "rawvideo",
          "-pix_fmt",
          pixel_format,
          "-i",
          "-",
          filename,
      ]
  
      if logfile:
          log_file = open(filename + ".log", "w+")
      else:
          log_file = sp.PIPE
  
      popen_params = cross_platform_popen_params(
          {"stdout": sp.DEVNULL, "stderr": log_file, "stdin": sp.PIPE}
      )
  
      proc = sp.Popen(cmd, **popen_params)
      out, err = proc.communicate(image.tobytes())
  
      if proc.returncode:
          error = (
              f"{err}\n\nMoviePy error: FFMPEG encountered the following error while "
              f"writing file {filename} with command {cmd}:\n\n {err.decode()}"
          )
  
          raise IOError(error)
  
      del proc
  
file_path: moviepy/moviepy/video/io/ffmpeg_writer.py
imports: import subprocess
  import numpy
  from proglog import proglog
  from moviepy.config import FFMPEG_BINARY
  from moviepy.tools import cross_platform_popen_params
label_desc: Use image node_id 2 for calling a global function with example usage: ffmpeg_write_image(filename, image, logfile, pixel_format) without return types