Skip to content

Instantly share code, notes, and snippets.

@cGuille
Created November 18, 2017 10:49
Show Gist options
  • Save cGuille/45e96e7f0d858efc7f593828e13387e1 to your computer and use it in GitHub Desktop.
Save cGuille/45e96e7f0d858efc7f593828e13387e1 to your computer and use it in GitHub Desktop.
Convert videos to GIF using ffmpeg and gifski.
#!/usr/bin/env bash
video_file_path="$1"
from="$2"
to="$3"
set -error
tmpdir_path="${TMPDIR:-/tmp}/"
video_file_name="$(basename "$video_file_path")"
dest_name="${video_file_name%.*}".gif
frame_file_name_prefix="$(mktemp -u "vidtogif_XXXXXXXXXX_${video_file_name}_frame")"
ffmpeg_input_opts=""
if [[ $from ]]; then
ffmpeg_input_opts="$ffmpeg_input_opts -ss $from"
fi
if [[ $to ]]; then
ffmpeg_input_opts="$ffmpeg_input_opts -to $to"
fi
ffmpeg $ffmpeg_input_opts -i "$video_file_path" "$tmpdir_path""$frame_file_name_prefix"_%04d.png
gifski -o "$dest_name" "$tmpdir_path""$frame_file_name_prefix"*
rm "$tmpdir_path""$frame_file_name_prefix"*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment