Skip to content

Instantly share code, notes, and snippets.

@jcelerier
Last active Nov 3, 2020
Embed
What would you like to do?
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