Skip to content

Instantly share code, notes, and snippets.

@bion
Created December 13, 2016 01:17
Show Gist options
  • Select an option

  • Save bion/9eac8a53490ebb46fdf77cb6b0f8f826 to your computer and use it in GitHub Desktop.

Select an option

Save bion/9eac8a53490ebb46fdf77cb6b0f8f826 to your computer and use it in GitHub Desktop.
animated gif CLI tools
#!/bin/sh
set -e
if [ "$#" -ne 4 ]; then
echo Usage:
echo "\textract-snippet INPUT_FILE OUTPUT_FILE START_TIME DURATION_SECONDS"
echo "\te.g. extract-snippet full-video.mkv snippet.mkv 00:24:17 5"
exit 1
fi
input_file=$1
output_file=$2
start_time=$3
duration_seconds=$4
printf "snipping $duration_seconds seconds starting at $start_time of $input_file to $output_file..."
ffmpeg -ss $start_time \
-t $duration_seconds \
-i $input_file \
-c:v copy \
-map 0:v \
-y $output_file &> /dev/null
echo " done!"
#!/bin/sh
set -e
if [ "$#" -ne 2 ]; then
echo Usage:
echo "\tgif-encode INPUT_FILE OUTPUT_FILE"
exit 1
fi
palette="/tmp/palette.png"
filters="fps=15,scale=640:-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
rm $palette
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment