code: def insert_in_background(
      video_path: str,
      output_path: Optional[str] = None,
      background_path: Optional[str] = None,
      offset_factor: float = 0.0,
      source_percentage: Optional[float] = None,
      seed: Optional[int] = None,
      transition: Optional[af.TransitionConfig] = None,
      metadata: Optional[List[Dict[str, Any]]] = None,
  ) -> str:
      """
      Puts the video in the middle of the background video
      (at offset_factor * background.duration)
  
      @param video_path: the path to the video to be augmented
  
      @param output_path: the path in which the resulting video will be stored.
          If not passed in, the original video file will be overwritten
  
      @param background_path: the path to the video in which to insert the main
          video. If set to None, the main video will play in the middle of a silent
          video with black frames
  
      @param offset_factor: the point in the background video in which the main video
          starts to play (this factor is multiplied by the background video duration to
          determine the start point)
  
      @param source_percentage: when set, source_percentage of the duration
          of the final video (background + source) will be taken up by the
          source video. Randomly crops the background video to the correct duration.
          If the background video isn't long enough to get the desired source_percentage,
          it will be looped.
  
      @param seed: if provided, this will set the random seed to ensure consistency
          between runs
  
      @param transition: optional transition configuration to apply between the clips
  
      @param metadata: if set to be a list, metadata about the function execution including
          its name, the source & dest duration, fps, etc. will be appended to the inputted
          list. If set to None, no metadata will be appended or returned
  
      @returns: the path to the augmented video
      """
      assert (
          0.0 <= offset_factor <= 1.0
      ), "Offset factor must be a value in the range [0.0, 1.0]"
  
      if source_percentage is not None:
          assert (
              0.0 <= source_percentage <= 1.0
          ), "Source percentage must be a value in the range [0.0, 1.0]"
  
      func_kwargs = helpers.get_func_kwargs(
          metadata, locals(), video_path
      )
      local_path = utils.pathmgr.get_local_path(video_path)
      utils.validate_video_path(local_path)
  
      video_info = helpers.get_video_info(local_path)
      video_duration = float(video_info["duration"])
      width, height = video_info["width"], video_info["height"]
  
      rng = (
          np.random.RandomState(seed) if seed is not None else np.random
      )
  
      video_paths = []
      with tempfile.TemporaryDirectory() as tmpdir:
          tmp_video_path = os.path.join(tmpdir, "in.mp4")
          resized_bg_path = os.path.join(tmpdir, "bg.mp4")
  
          helpers.add_silent_audio(video_path, tmp_video_path)
  
          if background_path is None:
              helpers.create_color_video(
                  resized_bg_path, video_duration, height, width
              )
          else:
              resize(background_path, resized_bg_path, height, width)
  
          bg_video_info = helpers.get_video_info(resized_bg_path)
          bg_video_duration = float(bg_video_info["duration"])
  
          bg_start = 0
          bg_end = bg_video_duration
          desired_bg_duration = bg_video_duration
          if source_percentage is not None:
              # desired relationship: percent * (bg_len + s_len) = s_len
              # solve for bg_len -> bg_len = s_len / percent - s_len
              desired_bg_duration = (
                  video_duration / source_percentage - video_duration
              )
  
              # if background vid isn't long enough, loop
              num_loops_needed = math.ceil(
                  desired_bg_duration / bg_video_duration
              )
              if num_loops_needed > 1:
                  loop(resized_bg_path, num_loops=num_loops_needed)
                  bg_video_duration *= num_loops_needed
  
              bg_start = rng.uniform(
                  0, bg_video_duration - desired_bg_duration
              )
              bg_end = bg_start + desired_bg_duration
  
          offset = desired_bg_duration * offset_factor
  
          transition_before = False
          if offset > 0:
              before_path = os.path.join(tmpdir, "before.mp4")
              trim(
                  resized_bg_path,
                  before_path,
                  start=bg_start,
                  end=bg_start + offset,
              )
              video_paths.append(before_path)
              src_video_path_index = 1
              transition_before = True
          else:
              src_video_path_index = 0
  
          video_paths.append(tmp_video_path)
  
          transition_after = False
          if bg_start + offset < bg_end:
              after_path = os.path.join(tmpdir, "after.mp4")
              trim(
                  resized_bg_path,
                  after_path,
                  start=bg_start + offset,
                  end=bg_end,
              )
              video_paths.append(after_path)
              transition_after = True
  
          concat(
              video_paths,
              output_path or video_path,
              src_video_path_index,
              transition=transition,
          )
  
      if metadata is not None:
          helpers.get_metadata(
              metadata=metadata,
              function_name="insert_in_background",
              background_video_duration=desired_bg_duration,
              transition_before=transition_before,
              transition_after=transition_after,
              **func_kwargs,
          )
  
      return output_path or video_path
  
imports: import functools
  import math
  import os
  import shutil
  import tempfile
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import numpy
  from augly import audio, image, utils
  from augly.audio import utils
  from augly.video import helpers, utils
  from augly.video.augmenters import cv2, ffmpeg
label_desc: Use image node_id 19 for calling a global function with example usage: insert_in_background(video_path, output_path, background_path, offset_factor, source_percentage, seed, transition, metadata) and returns: unknown