code: def _generate_video(
      out_file,
      n_frames=5,
      width=100,
      height=50,
      seed=0,
      fps=24,
      broken=False,
  ):
      """Generate a video.
  
      Use .avi extension if you want to save a lossless video. Use '.mpeg' for
      videos which should have streams.frames = 0, so that the whole video must
      be loaded to find the total number of frames. Note that mpeg requires
      fps = 24.
  
      """
      is_mpeg = out_file.endswith(".mpeg")
      video_format = "libx264rgb"
      pixel_format = "rgb24"
  
      if is_mpeg:
          video_format = "mpeg1video"
          pixel_format = "yuv420p"
  
      if broken:
          n_frames = 0
  
      np.random.seed(seed)
      container = av.open(out_file, mode="w")
      stream = container.add_stream(video_format, rate=fps)
      stream.width = width
      stream.height = height
      stream.pix_fmt = pixel_format
  
      if is_mpeg:
          frames = [
              av.VideoFrame(width, height, pixel_format)
              for i in range(n_frames)
          ]
      else:
          # save lossless video
          stream.options["crf"] = "0"
          images = (
              np.random.randn(n_frames, height, width, 3) * 255
          ).astype(np.uint8)
          frames = [
              av.VideoFrame.from_ndarray(image, format=pixel_format)
              for image in images
          ]
  
      for frame in frames:
          for packet in stream.encode(frame):
              container.mux(packet)
  
      if not broken:
          # flush the stream
          # video cannot be loaded if this is omitted
          packet = stream.encode(None)
          container.mux(packet)
  
      container.close()
  
      pil_images = [frame.to_image() for frame in frames]
      return pil_images
  
imports: import json
  import os
  import sys
  import tempfile
  import unittest
  import warnings
  from io import BytesIO
  from unittest import mock
  import numpy
  import tqdm
  from PIL import Image
  import lightly
label_desc: Use image node_id 4 for calling a global function with example usage: _generate_video(out_file, n_frames, width, height, seed, fps, broken) and returns: pil_images