Advertisement
Guest User

keyframe.py

a guest
Feb 13th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. import argparse
  2. import pathlib
  3.  
  4. import vapoursynth as vs
  5.  
  6. core = vs.core
  7.  
  8. parser = argparse.ArgumentParser()
  9. parser.add_argument('--use-scxvid', action='store_true', help="use Scxvid instead of WWXD to detect scene changes")
  10. parser.add_argument('--use-slices', action='store_true', help="when using Scxvid, speeds things up at the cost of differences in scene detection")
  11. 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")
  12. parser.add_argument('clip', help="the input video file")
  13. args = parser.parse_args()
  14.  
  15. out_path = args.out_file or str(pathlib.Path(args.clip).parent / "keyframe.txt")
  16. use_scxvid = args.use_scxvid
  17.  
  18. clip = core.lsmas.LWLibavSource(source=args.clip)
  19. clip = core.resize.Bilinear(clip, 640, 360, format=vs.YUV420P8)  # speed up the analysis by resizing first
  20. clip = core.scxvid.Scxvid(clip, use_slices=args.use_slices) if use_scxvid else core.wwxd.WWXD(clip)
  21. out_txt = "# keyframe format v1\nfps 0\n"
  22. for i in range(clip.num_frames):
  23.     props = clip.get_frame(i).props
  24.     scenechange = props._SceneChangePrev if use_scxvid else props.Scenechange
  25.     if scenechange:
  26.         out_txt += f"{i}\n"
  27.     if i % 1000 == 0:
  28.         print(i)
  29.  
  30. with open(out_path, 'w') as f:
  31.     f.write(out_txt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement