Breakthrough/PySceneDetect

Inconsistent scene result between CLI and python code

teyou opened this issue · 3 comments

teyou commented

Description:

There is an inconsistency between the output from CLI and python code while executing the same logic.
It is expected to return 1 scene instead of 0 from running via python code

Command:

CLI

scenedetect -i test.mp4 detect-content --threshold 27.0 list-scenes 

Its output as below

PySceneDetect] PySceneDetect 0.6.2
[PySceneDetect] Scene list filename format:
  $VIDEO_NAME-Scenes.csv
[PySceneDetect] Detecting scenes...                                                                                                                                                                              
Detected: 0 | Progress: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 901/901 [00:00<00:00, 1645.94frames/s]
[PySceneDetect] Processed 901 frames in 0.9 seconds (average 970.58 FPS).
[PySceneDetect] Detected 1 scenes, average shot length 30.0 seconds.
[PySceneDetect] Writing scene list to CSV file:
  1-Scenes.csv
[PySceneDetect] Scene List:
-----------------------------------------------------------------------
 | Scene # | Start Frame |  Start Time  |  End Frame  |   End Time   |
-----------------------------------------------------------------------
 |      1  |           1 | 00:00:00.000 |         901 | 00:00:30.033 |
-----------------------------------------------------------------------

Python Code

test.py
--- 

import scenedetect as sd


video = sd.open_video('test.mp4')
sm = sd.SceneManager()
sm.add_detector(sd.ContentDetector(threshold=27.0))
sm.detect_scenes(video, show_progress=True)
scene_list = sm.get_scene_list()
print(f"scene_list: {scene_list}")

Output as blow

scene_list: []

Environment:

pip install scenedetect
pip install opencv-python

Media/Files:

test.mp4

To quote @Breakthrough:

You can set start_in_scene=True to always get at least one scene back 🙂 This happens by default when using the CLI, but must be explicit when using the Python API.

https://www.scenedetect.com/docs/latest/api.html#module-scenedetect

Ah, I see you're building the SceneManager directly, rather than using the detect() method thats available. In that case you should update your call to get_scene_list() to get_scene_list(start_in_scene=True)

teyou commented

oh great, thanks @fullstackfool for your input!

For anyone who want to find the doc, here's the link : https://www.scenedetect.com/docs/latest/api/scene_manager.html#scenedetect.scene_manager.SceneManager.get_scene_list