我已经开始使用 PySceneDetect,它使用 OpenCV,特别是 cv2。在命令行中运行我的脚本时,它工作得非常好(参见截图 1):帧速率稳定,处理视频几乎不需要时间。 使用 Python IDLE 时,相同的脚本会遇到内存泄漏(参见截图 2)。 IDLE 的偏好设置中是否有我需要更改的设置,或者还有其他我没有考虑的设置?
import moviepy
from scenedetect import VideoManager
from scenedetect import SceneManager
from scenedetect.detectors import ContentDetector
video_title = "video.mp4"
def find_scenes(video_path, threshold=5.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)
# Each returned scene is a tuple of the (start, end) timecode.
return scene_manager.get_scene_list()
print(find_scenes(video_title))