Created
July 23, 2013 07:28
-
-
Save jsundram/6060474 to your computer and use it in GitHub Desktop.
Create an mp4 from the files in the input directory given. If there aren't a ton, make an animated gif. Assumes ImageMagick (for animated gif) or mjpegtools and ffmpeg for H264-encoded mp4.
This file contains 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
from glob import glob | |
import sys | |
from tempfile import NamedTemporaryFile | |
png_dir = sys.argv[1] | |
wildcard = os.path.join(png_dir, '*.png') | |
n = len(glob(wildcard)) | |
if n < 100: | |
# for short files, animated gifs are preferable | |
subprocess.call("convert -delay 2 -loop 0 %s output.gif" % wildcard).split(" "), cwd=png_dir) | |
else: | |
with NamedTemporaryFile(suffix='.yuv') as f: | |
# http://wiki.webmproject.org/howtos/convert-png-frames-to-webm-video | |
subprocess.call(("png2yuv -I p -f 24 -b 0 -n %d -j %%06d.png" % n).split(" "), cwd=png_dir, stdout=f) | |
subprocess.call(("ffmpeg -i %s -vcodec libx264 -tune animation output_video.mp4" % f.name).split(" "), cwd=png_dir) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment