Perform main CLI application control logic. Run once all command-line options and configuration file options have been validated. Arguments: context: Prevalidated command-line option context to use for processing.
(context: CliContext)
| 28 | |
| 29 | |
| 30 | def run_scenedetect(context: CliContext): |
| 31 | """Perform main CLI application control logic. Run once all command-line options and |
| 32 | configuration file options have been validated. |
| 33 | |
| 34 | Arguments: |
| 35 | context: Prevalidated command-line option context to use for processing. |
| 36 | """ |
| 37 | # No input may have been specified depending on the commands/args that were used. |
| 38 | logger.debug("Running controller.") |
| 39 | if context.scene_manager is None: |
| 40 | logger.debug("No input specified.") |
| 41 | return |
| 42 | |
| 43 | # Suppress warnings when reading past EOF in MoviePy (#461). |
| 44 | if VideoStreamMoviePy and isinstance(context.video_stream, VideoStreamMoviePy): |
| 45 | is_debug = context.config.get_value("global", "verbosity") != "debug" |
| 46 | if not is_debug: |
| 47 | warnings.filterwarnings("ignore", module="moviepy") |
| 48 | |
| 49 | if context.load_scenes_input: |
| 50 | # Skip detection if load-scenes was used. |
| 51 | logger.info("Skipping detection, loading scenes from: %s", context.load_scenes_input) |
| 52 | if context.stats_file_path: |
| 53 | logger.warning("WARNING: -s/--stats will be ignored due to load-scenes.") |
| 54 | scenes, cuts = _load_scenes(context) |
| 55 | scenes = _postprocess_scene_list(context, scenes) |
| 56 | logger.info("Loaded %d scenes.", len(scenes)) |
| 57 | else: |
| 58 | # Perform scene detection on input. |
| 59 | result = _detect(context) |
| 60 | if result is None: |
| 61 | return |
| 62 | scenes, cuts = result |
| 63 | scenes = _postprocess_scene_list(context, scenes) |
| 64 | # Handle -s/--stats option. |
| 65 | _save_stats(context) |
| 66 | if scenes: |
| 67 | logger.info( |
| 68 | "Detected %d scenes, average shot length %.1f seconds.", |
| 69 | len(scenes), |
| 70 | sum([(end_time - start_time).seconds for start_time, end_time in scenes]) |
| 71 | / float(len(scenes)), |
| 72 | ) |
| 73 | else: |
| 74 | logger.info("No scenes detected.") |
| 75 | |
| 76 | # Handle post-processing commands the user wants to run (see scenedetect._cli.commands). |
| 77 | for handler, kwargs in context.commands: |
| 78 | handler(context=context, scenes=scenes, cuts=cuts, **kwargs) |
| 79 | |
| 80 | |
| 81 | def _postprocess_scene_list(context: CliContext, scene_list: SceneList) -> SceneList: |
no test coverage detected