Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- import pathlib
- import vapoursynth as vs
- core = vs.core
- parser = argparse.ArgumentParser()
- parser.add_argument('--use-scxvid', action='store_true', help="use Scxvid instead of WWXD to detect scene changes")
- parser.add_argument('--use-slices', action='store_true', help="when using Scxvid, speeds things up at the cost of differences in scene detection")
- parser.add_argument('--out-file', help="the file to write scene changes to (Aegisub format); defaults to 'keyframes.txt' in the same directory as the input video file")
- parser.add_argument('clip', help="the input video file")
- args = parser.parse_args()
- out_path = args.out_file or str(pathlib.Path(args.clip).parent / "keyframe.txt")
- use_scxvid = args.use_scxvid
- clip = core.lsmas.LWLibavSource(source=args.clip)
- clip = core.resize.Bilinear(clip, 640, 360, format=vs.YUV420P8) # speed up the analysis by resizing first
- clip = core.scxvid.Scxvid(clip, use_slices=args.use_slices) if use_scxvid else core.wwxd.WWXD(clip)
- out_txt = "# keyframe format v1\nfps 0\n"
- for i in range(clip.num_frames):
- props = clip.get_frame(i).props
- scenechange = props._SceneChangePrev if use_scxvid else props.Scenechange
- if scenechange:
- out_txt += f"{i}\n"
- if i % 1000 == 0:
- print(i)
- with open(out_path, 'w') as f:
- f.write(out_txt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement