Created
September 22, 2014 22:42
-
-
Save danvk/ea7a9e2cd8cde9c92a5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
DEPENDENCIES: | |
$ brew install ffmpeg | |
$ brew install imagemagick | |
$ python ./mov2gif.py input.mov output.gif 15 | |
''' | |
import sys | |
import os | |
import tempfile | |
import shutil | |
import subprocess | |
if len(sys.argv) <= 2: | |
print 'usage: ', sys.argv[0], '[INPUT_MOV_FILENAME]', '[OUTPUT_GIF_FILENAME]', '[FPS]' | |
sys.exit(-1) | |
assert(os.path.exists(sys.argv[1])) | |
INPUT_MOV_FILENAME = sys.argv[1] | |
OUTPUT_GIF_FILENAME = sys.argv[2] | |
try: | |
FPS = int(sys.argv[3]) | |
except Exception, e: | |
FPS = 10 | |
temp = tempfile.mkdtemp() | |
TEMP = os.path.join(temp, '%5d.png') | |
subprocess.check_call( | |
['ffmpeg', '-loglevel', 'quiet', '-i', INPUT_MOV_FILENAME, '-r', str(FPS), TEMP]) | |
subprocess.check_call( | |
['convert', '-delay', '1x%si' % FPS, os.path.join(temp, '*.png'), OUTPUT_GIF_FILENAME]) | |
shutil.rmtree(temp) | |
cmd = 'open -R %(OUTPUT_GIF_FILENAME)s' % { | |
"OUTPUT_GIF_FILENAME": OUTPUT_GIF_FILENAME | |
} | |
subprocess.check_call(cmd, shell=True) | |
print 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment