code: def apply_to_frames(
      img_aug_function: functools.partial,
      video_path: str,
      second_video_path: str,
      output_path: Optional[str],
      use_second_audio: bool = False,
  ) -> None:
      video_path, output_path = helpers.validate_input_and_output_paths(
          video_path, output_path
      )
      second_video_path = helpers.get_local_path(second_video_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)
  
          second_frame_dir = os.path.join(tmpdir, "second_video_frames")
          os.mkdir(second_frame_dir)
          helpers.extract_frames_to_dir(
              second_video_path, second_frame_dir
          )
  
          for frame_file, second_frame_file in zip(
              os.listdir(frame_dir), os.listdir(second_frame_dir)
          ):
              img_aug_function(
                  os.path.join(frame_dir, frame_file),
                  os.path.join(second_frame_dir, second_frame_file),
                  output_path=os.path.join(frame_dir, frame_file),
              )
  
          audio_path = None
          if not use_second_audio and helpers.has_audio_stream(
              video_path
          ):
              audio_path = os.path.join(tmpdir, "audio.aac")
              helpers.extract_audio_to_file(video_path, audio_path)
          elif use_second_audio and helpers.has_audio_stream(
              second_video_path
          ):
              audio_path = os.path.join(tmpdir, "audio.aac")
              helpers.extract_audio_to_file(
                  second_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 2 for calling a global function with example usage: apply_to_frames(img_aug_function, video_path, second_video_path, output_path, use_second_audio) without return types