Last active
May 6, 2022 13:39
-
-
Save Breakthrough/494894e49cce59acd39301254fa5a849 to your computer and use it in GitHub Desktop.
PySceneDetect JSON Output Example for @kusalavan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from scenedetect import VideoManager | |
from scenedetect import SceneManager | |
from scenedetect.detectors import ContentDetector | |
from scenedetect.scene_manager import save_images | |
def get_scenes_json(video_path, threshold=30.0): | |
# Create our video & scene managers, then add the detector. | |
video_manager = VideoManager([video_path]) | |
scene_manager = SceneManager() | |
scene_manager.add_detector( | |
ContentDetector(threshold=threshold)) | |
# Improve processing speed by downscaling before processing. | |
video_manager.set_downscale_factor() | |
# Start the video manager and perform the scene detection. | |
video_manager.start() | |
scene_manager.detect_scenes(frame_source=video_manager) | |
# Detection complete, get list of scenes. | |
scene_list = scene_manager.get_scene_list() | |
# Save one image per scene. | |
save_images(scene_list=scene_list, video_manager=video_manager, num_images=1) | |
# Format and output scene list in JSON. | |
print(json.dumps( | |
[ | |
{"scene_number": i+1, | |
"start_time": s[0].get_timecode(), | |
"end_time": s[1].get_timecode() | |
} for (i, s) in enumerate(scene_list) ] | |
)) | |
get_scenes_json('goldeneye.mp4') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment