Skip to content

Instantly share code, notes, and snippets.

@warpling
Last active July 6, 2025 12:32
Show Gist options
  • Save warpling/2e7bb1bab1acc95ac1f6cc152bf46fd0 to your computer and use it in GitHub Desktop.
Save warpling/2e7bb1bab1acc95ac1f6cc152bf46fd0 to your computer and use it in GitHub Desktop.
A python script for splitting up movies into distinct scenes
#!/usr/bin/env python3
"""
Slice a long VHS-rip MP4 into individual clips using PySceneDetect + ffmpeg.
Usage: python vhs_slice.py input.mp4 [--out out_dir] [--threshold 35]
If there are too many scenes try increasing threshold, and vice versa
To run this script you'll need to use a python environment manager to install and manage the necessary dependencies
"""
import argparse, os, subprocess, sys
from scenedetect import SceneManager, open_video, ContentDetector
from scenedetect.video_splitter import split_video_ffmpeg
def detect_scenes(path, thresh):
video = open_video(path)
sm = SceneManager()
sm.add_detector(ContentDetector(threshold=thresh))
sm.detect_scenes(video)
return sm.get_scene_list()
def main():
p = argparse.ArgumentParser()
p.add_argument("input")
p.add_argument("--out", default="clips")
p.add_argument("--threshold", type=float, default=27)
args = p.parse_args()
os.makedirs(args.out, exist_ok=True)
scenes = detect_scenes(args.input, args.threshold)
if not scenes:
sys.exit("No cuts found—try a lower threshold.")
split_video_ffmpeg(args.input, scenes, output_dir=args.out,
output_file_template="Scene-$SCENE_NUMBER.mp4",
show_progress=True)
print(f"Done. {len(scenes)} clips in {args.out}/")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment