Skip to content

Instantly share code, notes, and snippets.

@luser
Created February 12, 2015 11:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save luser/0dc0f03637b6b30f4bb2 to your computer and use it in GitHub Desktop.
Save luser/0dc0f03637b6b30f4bb2 to your computer and use it in GitHub Desktop.
moviepy gif loop finder
#!/usr/bin/env python
# Taken from http://zulko.github.io/blog/2015/02/01/extracting-perfectly-looping-gifs-from-videos-with-python-and-moviepy/
import os
import sys
import moviepy.editor as mp
from moviepy.video.tools.cuts import FramesMatches
if len(sys.argv) != 2:
print "makegifs.py <video file>"
sys.exit(1)
clip = mp.VideoFileClip(sys.argv[1])
name = os.path.splitext(os.path.basename(sys.argv[1]))[0]
scenes = FramesMatches.from_clip(clip.resize(width=120), 5, 2)
selected_scenes = scenes.select_scenes(2, 0.5, 4, 0.5)
os.mkdir(name)
selected_scenes.write_gifs(clip.resize(width=270), name)
@Zulko
Copy link

Zulko commented Feb 12, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment