Skip to content

Instantly share code, notes, and snippets.

@mlubej
Last active January 22, 2021 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlubej/8271e61bcc2bfed583e94f64db85440d to your computer and use it in GitHub Desktop.
Save mlubej/8271e61bcc2bfed583e94f64db85440d to your computer and use it in GitHub Desktop.
gif_maker.py
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