code: def seg_video(args):
      assert os.path.exists(
          args.video_path
      ), "The --video_path is not existed: {}".format(args.video_path)
      assert args.save_dir.endswith(
          ".avi"
      ), "The --save_dir should be xxx.avi"
  
      cap_img = cv2.VideoCapture(args.video_path)
      assert cap_img.isOpened(), "Fail to open video:{}".format(
          args.video_path
      )
      fps = cap_img.get(cv2.CAP_PROP_FPS)
      total_frames = int(cap_img.get(cv2.CAP_PROP_FRAME_COUNT))
      width = int(cap_img.get(cv2.CAP_PROP_FRAME_WIDTH))
      height = int(cap_img.get(cv2.CAP_PROP_FRAME_HEIGHT))
      cap_out = cv2.VideoWriter(
          args.save_dir,
          cv2.VideoWriter_fourcc("M", "J", "P", "G"),
          fps,
          (width, height),
      )
  
      if args.bg_video_path is not None:
          assert os.path.exists(
              args.bg_video_path
          ), "The --bg_video_path is not existed: {}".format(
              args.bg_video_path
          )
          is_video_bg = True
          cap_bg = cv2.VideoCapture(args.bg_video_path)
          assert cap_bg.isOpened(), "Fail to open video:{}".format(
              args.bg_video_path
          )
          bg_frame_nums = cap_bg.get(cv2.CAP_PROP_FRAME_COUNT)
          bg_frame_idx = 1
      else:
          is_video_bg = False
          bg = get_bg_img(args.bg_img_path, [height, width, 3])
  
      logger.info("Input: video")
      logger.info("Create predictor...")
      predictor = Predictor(args)
  
      logger.info("Start predicting...")
      with tqdm(total=total_frames) as pbar:
          img_frame_idx = 0
          while cap_img.isOpened():
              ret_img, img = cap_img.read()
              if not ret_img:
                  break
  
              if is_video_bg:
                  ret_bg, bg = cap_bg.read()
                  if not ret_bg:
                      break
                  bg_frame_idx += 1
                  if bg_frame_idx == bg_frame_nums:
                      bg_frame_idx = 1
                      cap_bg.set(cv2.CAP_PROP_POS_FRAMES, 0)
  
              out = predictor.run(img, bg)
              cap_out.write(out)
              img_frame_idx += 1
              pbar.update(1)
  
      cap_img.release()
      cap_out.release()
      if is_video_bg:
          cap_bg.release()
  
file_path: PaddleSeg/contrib/PP-HumanSeg/src/seg_demo.py
imports: import argparse
  import os
  import sys
  import cv2
  import numpy
  from tqdm import tqdm
  from paddleseg.utils import get_sys_env, logger, get_image_list
  from infer import Predictor
label_desc: Use image node_id 5 for calling a global function with example usage: seg_video(args) without return types