code: def apply_to_each_frame(
      img_aug_function: functools.partial,
      video_path: str,
      output_path: Optional[str],
      frame_func: Optional[Callable[[int], Dict]] = None,
  ) -> None:
      video_path, output_path = helpers.validate_input_and_output_paths(
          video_path, output_path
      )
  
      with tempfile.TemporaryDirectory() as tmpdir:
          frame_dir = os.path.join(tmpdir, "video_frames")
          os.mkdir(frame_dir)
          helpers.extract_frames_to_dir(video_path, frame_dir)
  
          for i, frame_file in enumerate(os.listdir(frame_dir)):
              frame_path = os.path.join(frame_dir, frame_file)
              kwargs = frame_func(i) if frame_func is not None else {}
              img_aug_function(
                  frame_path, output_path=frame_path, **kwargs
              )
  
          audio_path = None
          if helpers.has_audio_stream(video_path):
              audio_path = os.path.join(tmpdir, "audio.aac")
              helpers.extract_audio_to_file(video_path, audio_path)
  
          helpers.combine_frames_and_audio_to_file(
              os.path.join(frame_dir, "raw_frame*.jpg"),
              audio_path,
              output_path,
              helpers.get_video_fps(video_path)
              or utils.DEFAULT_FRAME_RATE,
          )
  
file_path: AugLy/augly/video/utils.py
imports: import functools
  import os
  import shutil
  import tempfile
  from typing import Callable, Dict, List, Optional, Union
  from augly import utils
  from augly.video import helpers
  from augly.video.augmenters import cv2
label_desc: Use image node_id 1 for calling a global function with example usage: apply_to_each_frame(img_aug_function, video_path, output_path, frame_func) without return types