(args)
| 330 | |
| 331 | |
| 332 | def process_input_video(args): |
| 333 | args_dict = vars(args) |
| 334 | print(args_dict) |
| 335 | |
| 336 | assert len(args.resolution_area) == 2, "resolution_area should be a list of two integers [width, height]" |
| 337 | assert args.video_path is not None, "--video_path is required" |
| 338 | assert args.save_path is not None, "--save_path is required" |
| 339 | if args.mode == "pose": |
| 340 | assert args.ckpt_path is not None, "--ckpt_path is required when --mode pose" |
| 341 | |
| 342 | pipeline = None |
| 343 | if args.mode == "pose": |
| 344 | det_checkpoint_path = os.path.join(args.ckpt_path, "det/yolox_l.onnx") |
| 345 | pose2d_checkpoint_path = os.path.join(args.ckpt_path, "pose2d/dw-ll_ucoco_384.onnx") |
| 346 | pipeline = DWPosePipeline( |
| 347 | det_checkpoint_path=det_checkpoint_path, |
| 348 | pose2d_checkpoint_path=pose2d_checkpoint_path, |
| 349 | device=args.device, |
| 350 | ) |
| 351 | |
| 352 | video_reader = VideoReader(args.video_path) |
| 353 | frame_num = len(video_reader) |
| 354 | video_fps = video_reader.get_avg_fps() |
| 355 | print(f"frame_num: {frame_num}") |
| 356 | print(f"video_fps: {video_fps}") |
| 357 | |
| 358 | duration = video_reader.get_frame_timestamp(-1)[-1] |
| 359 | expected_frame_num = int(duration * video_fps + 0.5) |
| 360 | ratio = abs((frame_num - expected_frame_num) / max(frame_num, 1)) |
| 361 | if ratio > 0.1: |
| 362 | print("Warning: actual frame count differs from expected by >10%; using duration-based estimate.") |
| 363 | frame_num = expected_frame_num |
| 364 | |
| 365 | target_fps = video_fps if args.fps == -1 else args.fps |
| 366 | if args.num_frames > 0: |
| 367 | target_num = args.num_frames |
| 368 | else: |
| 369 | target_num = int(frame_num / video_fps * target_fps) |
| 370 | target_num = max(snap_to_8k_plus_1(target_num), 1) |
| 371 | upper_bound = snap_to_8k_plus_1(int(frame_num / video_fps * target_fps)) |
| 372 | target_num = min(target_num, upper_bound) |
| 373 | print(f"target_num (snapped to 8k+1): {target_num}") |
| 374 | |
| 375 | idxs = get_frame_indices(frame_num, video_fps, target_num, target_fps) |
| 376 | frames = video_reader.get_batch(idxs).asnumpy() |
| 377 | |
| 378 | target_area = args.resolution_area[0] * args.resolution_area[1] |
| 379 | |
| 380 | if args.refer_path: |
| 381 | logger.info(f"Using --refer_path to drive canvas aspect: {args.refer_path}") |
| 382 | refer_bgr = cv2.imread(args.refer_path) |
| 383 | if refer_bgr is None: |
| 384 | raise ValueError(f"Failed to read --refer_path: {args.refer_path!r}") |
| 385 | refer_rgb = refer_bgr[..., ::-1] |
| 386 | refer_rgb = resize_by_area(refer_rgb, target_area, divisor=32) |
| 387 | height, width = refer_rgb.shape[:2] |
| 388 | # Fit each driving frame into the (height, width) canvas with letterboxing. |
| 389 | frames = [padding_resize(f, height=height, width=width) for f in frames] |
no test coverage detected