Breakthrough / PySceneDetect

:movie_camera: Python and OpenCV-based scene cut/transition detection program & library.
https://www.scenedetect.com/
BSD 3-Clause "New" or "Revised" License
2.97k stars 374 forks source link

Inconsistent scene result between CLI and python code #343

Closed teyou closed 11 months ago

teyou commented 11 months ago

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:

https://github.com/Breakthrough/PySceneDetect/assets/1115155/5b69d477-03ff-42ac-9232-7f34172051b0

fullstackfool commented 11 months ago

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

fullstackfool commented 11 months ago

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 11 months ago

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