Last active
January 31, 2016 18:41
-
-
Save seppo0010/7cb9e874ee9c53348cf4 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
palette="/tmp/palette.png" | |
filters="fps=15,scale=$3:-1:flags=lanczos" | |
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette | |
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2 |
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
#!/usr/bin/env python | |
from subprocess import call | |
import os | |
import sys | |
filename = sys.argv[1] | |
filename_target = filename + '.gif' | |
filesize_target = int(sys.argv[2] if len(sys.argv) > 2 else 5) * 1024 * 1024 | |
min_resolution, max_resolution = (100, 1124) | |
while min_resolution < max_resolution: | |
avg = (max_resolution + min_resolution) / 2 | |
call(('ffmpeg-gif.sh', filename, filename_target, str(avg))) | |
size = os.stat(filename_target).st_size | |
if size > filesize_target: | |
max_resolution = avg - 1 | |
elif size < filesize_target: | |
min_resolution = avg + 1 | |
else: | |
min_resolution = max_resolution = (avg, avg) | |
call(('ffmpeg-gif.sh', filename, filename_target, str(min(min_resolution, max_resolution)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment