Skip to content

Instantly share code, notes, and snippets.

@kyeongan
Created April 23, 2025 01:27
Show Gist options
  • Save kyeongan/e9d3f0689ef3f12d7d5362d2200cfe3a to your computer and use it in GitHub Desktop.
Save kyeongan/e9d3f0689ef3f12d7d5362d2200cfe3a to your computer and use it in GitHub Desktop.
Shell script to convert .mov video files into 5x speed, optimized GIFs using ffmpeg with palette generation for quality and size efficiency.
#!/bin/bash
# make_gif_5x.sh
# Convert a .mov file into an optimized 5x speed animated GIF using ffmpeg and palette method.
# Usage:
# ./make_gif_5x.sh input.mov
INPUT="$1"
BASENAME=$(basename "$INPUT" .mov)
FPS=10
SCALE=1000
SPEED=5
PTS=$(awk "BEGIN{print 1/$SPEED}")
if [[ -z "$INPUT" ]]; then
echo "❗ Usage: $0 input.mov"
exit 1
fi
echo "🎞️ Input: $INPUT"
echo "⚡ Speed: ${SPEED}x | FPS: ${FPS} | Width: ${SCALE}px"
# Step 1: Generate color palette
ffmpeg -i "$INPUT" -filter_complex \
"[0:v]setpts=${PTS}*PTS,fps=${FPS},scale=${SCALE}:-1:flags=lanczos,palettegen" \
-y palette.png
# Step 2: Generate GIF using the palette
ffmpeg -i "$INPUT" -i palette.png -filter_complex \
"[0:v]setpts=${PTS}*PTS,fps=${FPS},scale=${SCALE}:-1:flags=lanczos[x];[x][1:v]paletteuse" \
-y "${BASENAME}_${SPEED}x.gif"
# Cleanup
rm -f palette.png
echo "✅ Done: ${BASENAME}_${SPEED}x.gif"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment