code: def write_audio_video(path, video, audio, fps=30, audio_rate=48000):
      video_array = torch.as_tensor(video, dtype=torch.uint8).numpy()
      audio_array = audio.numpy().astype("<i2")
  
      with av.open(path, "w") as container:
          # Add lossless h264 video stream.
          video_stream = container.add_stream("libx264rgb", fps)
          video_stream.width = video_array.shape[2]
          video_stream.height = video_array.shape[1]
          video_stream.pix_fmt = "rgb24"
          video_stream.options = {"crf": "0"}  # Lossless video option
  
          # Add lossless flac, stereo audio stream.
          audio_stream = container.add_stream(
              "flac", rate=audio_rate, layout="stereo"
          )
          audio_stream.codec_context.skip_frame = "NONE"
          audio_stream.time_base = f"1/{audio_rate}"
          audio_stream.options = {}
  
          num_audio_samples = audio_array.shape[-1]
          num_video_frames = len(video_array)
          num_audio_samples_per_frame = audio_rate // fps
          encoded_audio_index = 0
          encoded_video_index = 0
  
          # Video and audio stream packets are encoded interleaved by their time.
          # To do this we start both streams from pts 0 and then encode 1 video frame
          # and num_audio_samples_per_frame audio samples continuously until both
          # streams have finished encoding.
          while (
              encoded_audio_index < num_audio_samples
              or encoded_video_index < num_video_frames
          ):
              # Video frame encodings.
              if encoded_video_index < num_video_frames:
                  frame = video_array[encoded_video_index]
                  video_frame = av.VideoFrame.from_ndarray(
                      frame, format="rgb24"
                  )
                  video_frame.pict_type = "NONE"
                  encoded_video_index += 1
                  for packet in video_stream.encode(video_frame):
                      container.mux(packet)
  
              # Audio frame encodings.
              if encoded_audio_index < num_audio_samples:
                  encode_packet_end = (
                      encoded_audio_index + num_audio_samples_per_frame
                  )
                  audio_frame = av.AudioFrame.from_ndarray(
                      audio_array[
                          :, encoded_audio_index:encode_packet_end
                      ],
                      format="s16",
                      layout="stereo",
                  )
                  encoded_audio_index = encode_packet_end
                  audio_frame.rate = audio_rate
                  audio_frame.time_base = f"1/{audio_rate}"
                  encoded_packets = audio_stream.encode(audio_frame)
                  for packet in encoded_packets:
                      container.mux(packet)
  
          # Flush streams.
          for packet in audio_stream.encode(None):
              container.mux(packet)
  
          for packet in video_stream.encode(None):
              container.mux(packet)
  
file_path: pytorchvideo/tests/utils.py
imports: import contextlib
  import os
  import pathlib
  import tempfile
  import av
  import numpy
  import torch
  import torchvision.io
  import torchvision.transforms
  from pytorchvideo.data.dataset_manifest_utils import EncodedVideoInfo, VideoFrameInfo, VideoInfo
  from pytorchvideo.data.utils import thwc_to_cthw
label_desc: Use image node_id 7 for calling a global function with example usage: write_audio_video(path, video, audio, fps, audio_rate) without return types