Last active
January 22, 2021 21:56
-
-
Save mlubej/8271e61bcc2bfed583e94f64db85440d to your computer and use it in GitHub Desktop.
gif_maker.py
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
import ffmpeg | |
# video related | |
stream = ffmpeg.input('<INPUT_IMAGES>', pattern_type='glob', framerate=<FPS>) # load image stream | |
stream = stream.filter('pad', w='ceil(iw/2)*2', h='ceil(ih/2)*2', color='white') # pad the image | |
split = stream.split() # split for multiple usecases | |
video = split[0] # define the video stream | |
# gif related | |
palette = split[1].filter('palettegen', reserve_transparent=True, stats_mode='diff') # determine time-lapse specific color pallete to reduce dithering | |
gif = ffmpeg.filter([split[2], palette], 'paletteuse', dither='heckbert') # apply the pallete and define the gif stream | |
# save output | |
video.output('<VIDEO_OUTPUT>', crf=25, pix_fmt='yuv420p', vcodec='libx264', an=None).run(overwrite_output=True) # output video | |
gif.output('<GIF_OUTPUT>').run(overwrite_output=True) # output gif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment