Skip to content

Instantly share code, notes, and snippets.

@sujeong000
Last active May 8, 2023 14:38
Show Gist options
  • Save sujeong000/50c4beaf669bdfac455f41bf305fe14c to your computer and use it in GitHub Desktop.
Save sujeong000/50c4beaf669bdfac455f41bf305fe14c to your computer and use it in GitHub Desktop.
PySceneDetect를 활용한 Scene Transition Detection
from scenedetect import open_video, SceneManager
from scenedetect.detectors import ContentDetector
from scenedetect.scene_manager import save_images
from scenedetect.video_splitter import split_video_ffmpeg
# 영상 불러오기
video_path = '영상 파일명을 입력하세요'
video = open_video(video_path)
# 디텍터 생성, 임계값 30, 장면 당 최소 프레임 수 150
content_detector = ContentDetector(threshold=30, min_scene_len=150)
# Scene Manager 생성
scene_manager = SceneManager()
scene_manager.add_detector(content_detector)
# 디텍트 수행
scene_manager.detect_scenes(video, show_progress=True)
scene_list = scene_manager.get_scene_list()
# 장면 분할 결과 출력
for scene in scene_list:
start, end = scene
print(start, "~", end)
# 영상 자르기 (파일로 저장)
split_video_ffmpeg(video_path, scene_list, show_progress=True)
# 썸네일 만들기 (jpg 파일로 저장)
save_images(
scene_list, # 장면 리스트 [(시작, 끝)]
video, # 영상
num_images=1, # 각 장면 당 이미지 개수
image_name_template='$SCENE_NUMBER', # 결과 이미지 파일 이름
output_dir='thumbnails') # 결과 디렉토리 이름
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment