(
self,
input_path: str,
frame_rate: float | None,
backend: str | None,
)
| 488 | init_logger(log_level=curr_verbosity, show_stdout=not self.quiet_mode, log_file=logfile) |
| 489 | |
| 490 | def _open_video_stream( |
| 491 | self, |
| 492 | input_path: str, |
| 493 | frame_rate: float | None, |
| 494 | backend: str | None, |
| 495 | ): |
| 496 | if "%" in input_path and backend != "opencv": |
| 497 | raise click.BadParameter( |
| 498 | "The OpenCV backend (`--backend opencv`) must be used to process image sequences.", |
| 499 | param_hint="-i/--input", |
| 500 | ) |
| 501 | if frame_rate is not None and frame_rate < MAX_FPS_DELTA: |
| 502 | raise click.BadParameter("Invalid frame rate specified!", param_hint="-f/--frame-rate") |
| 503 | try: |
| 504 | backend = self.config.get_value("global", "backend", backend) |
| 505 | if backend not in AVAILABLE_BACKENDS: |
| 506 | raise click.BadParameter( |
| 507 | f"Specified backend {backend} is not available on this system!", |
| 508 | param_hint="-b/--backend", |
| 509 | ) |
| 510 | |
| 511 | # Open the video with the specified backend, loading any required config settings. |
| 512 | if backend == "pyav": |
| 513 | self.video_stream = open_video( |
| 514 | path=input_path, |
| 515 | frame_rate=frame_rate, |
| 516 | backend=backend, |
| 517 | threading_mode=self.config.get_value("backend-pyav", "threading-mode"), |
| 518 | suppress_output=self.config.get_value("backend-pyav", "suppress-output"), |
| 519 | ) |
| 520 | elif backend == "opencv": |
| 521 | self.video_stream = open_video( |
| 522 | path=input_path, |
| 523 | frame_rate=frame_rate, |
| 524 | backend=backend, |
| 525 | max_decode_attempts=self.config.get_value( |
| 526 | "backend-opencv", "max-decode-attempts" |
| 527 | ), |
| 528 | ) |
| 529 | # Handle backends without any config options. |
| 530 | else: |
| 531 | self.video_stream = open_video( |
| 532 | path=input_path, |
| 533 | frame_rate=frame_rate, |
| 534 | backend=backend, |
| 535 | ) |
| 536 | duration = self.video_stream.duration |
| 537 | duration_str = f"{duration} ({duration.frame_num} frames)" if duration else "unknown" |
| 538 | rate = self.video_stream.frame_rate |
| 539 | logger.debug(f"""Video information: |
| 540 | Backend: {type(self.video_stream).__name__} |
| 541 | Resolution: {self.video_stream.frame_size} |
| 542 | Frame rate: {float(rate):.3f} ({rate.numerator}/{rate.denominator}) |
| 543 | Duration: {duration_str}""") |
| 544 | |
| 545 | except FrameRateUnavailable as ex: |
| 546 | if DEBUG_MODE: |
| 547 | raise |
no test coverage detected