Skip to content

Instantly share code, notes, and snippets.

@jcelerier
Last active April 10, 2022 21:04
Show Gist options
  • Save jcelerier/6281455e3610b8707d65fa241ab0f8a2 to your computer and use it in GitHub Desktop.
Save jcelerier/6281455e3610b8707d65fa241ab0f8a2 to your computer and use it in GitHub Desktop.
Apply an audio lowpass on every frame of a gif
#!/bin/sh
# Invocation : script.sh name-of-the.gif
# Find out the size
SIZE=$(identify $1 | egrep --only-matching '[0-9]+x[0-9]+' | head -n 1)
mkdir -p frames
rm -rf frames/*
# Extract individual frames
convert $1 frames/%05d.png
(
cd frames
for frame in *.png; do
# Extract raw RGB data from the frames
stream -map rgb -storage-type short $frame $frame.raw
# Apply a lowpass filter
sox -r 8k -e signed -b 16 $frame.raw $frame.raw.raw lowpass 25
# Back to png
convert -size $SIZE -depth 16 rgb:$frame.raw.raw $frame
done
)
# Back to gif (likely we could have saved the PNG reconversion step but... lazy)
convert frames/*.png $1-out.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment