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

Can't get save_images to work #389

Closed adbmdp closed 2 months ago

adbmdp commented 2 months ago

Description:

I can't get save_images to work.

Example:

from scenedetect import open_video
from scenedetect.scene_manager import SceneManager, save_images
from scenedetect.detectors import ContentDetector

def detect_scenes(video_path, threshold=27.0):
    # Open the video
    video = open_video(video_path)

    # Create the scene manager
    scene_manager = SceneManager()

    # Add the content detector
    scene_manager.add_detector(ContentDetector(threshold=threshold))

    # Detect the scenes
    scene_manager.detect_scenes(video)

    scene_list = scene_manager.get_scene_list()

    scene_manager.save_images(scene_list, scene_manager, num_images=3, output_dir='images')

    # Get the list of detected scenes
    return scene_list

# Example usage
video_path = "https://www.mysite.com/my_video.mp4"
scene_list = detect_scenes(video_path)

for i, (start, end) in enumerate(scene_list):
    print(f"Scene {i+1}: {start.get_timecode()} - {end.get_timecode()}")

Environment:

[PySceneDetect] PySceneDetect 0.6.3

System Info
------------------------------------------------------------
OS           macOS-14.4.1-arm64-arm-64bit
Python       3.12.2

Packages
------------------------------------------------------------
av           Not Installed
click        8.1.7
cv2          4.9.0
moviepy      Not Installed
numpy        1.26.4
platformdirs 4.2.0
scenedetect  0.6.3
tqdm         4.66.2

Tools
------------------------------------------------------------
ffmpeg       Not Installed
mkvmerge     Not Installed

Media/Files:

Error : AttributeError: 'SceneManager' object has no attribute 'save_images'

Any help appreciated

adbmdp commented 2 months ago

Get it to work like this:

import scenedetect
from scenedetect import open_video
from scenedetect import SceneManager, save_images
from scenedetect.detectors import ContentDetector

def detect_scenes(video_path, threshold=27.0):
    # Open the video
    video = open_video(video_path)

    # Create the scene manager
    scene_manager = SceneManager()

    # Add the content detector
    scene_manager.add_detector(ContentDetector(threshold=threshold))

    # Detect the scenes
    scene_manager.detect_scenes(video)

    scene_list = scene_manager.get_scene_list()

    scenedetect.scene_manager.save_images(scene_list, video, num_images=3, output_dir='images')

    # Get the list of detected scenes
    return scene_list

# Example usage
video_path = "https://www.mysite.com/video.mp4"
scene_list = detect_scenes(video_path)

for i, (start, end) in enumerate(scene_list):
    print(f"Scene {i+1}: {start.get_timecode()} - {end.get_timecode()}")