ozwaldorf / lutgen-rs

Blazingly fast interpolated LUT generator and applicator for arbitrary and popular color palettes.
https://docs.rs/lutgen
MIT License
293 stars 8 forks source link

Add support for GIFs #25

Open Zai-Kun opened 2 months ago

Zai-Kun commented 2 months ago

Is adding support for GIFs possible? If so, then it would be nice to have it

Oughie commented 2 months ago

Since I wanted to set a GIF as wallpaper myself, I created a quick/dirty bash script to do this myself, using lutgen, imagemagick and ffmpeg:

#!/bin/bash

TARGET_GIF="$1"
# You might want to change these
TMP_DIR="tmp" # Directory to save each frame temporarily
OUT_GIF="out.gif"
PALETTE="catppuccin-mocha"
DELAY=10

rm -r "$TMP_DIR"
mkdir -p "$TMP_DIR"

ffmpeg -i "$TARGET_GIF" "$TMP_DIR/frame_%05d.png"

for file in "$TMP_DIR"/*.png; do
    lutgen apply -p "$PALETTE" "$file" -o "$file"
done

magick "$TMP_DIR"/*.png -set delay "$DELAY" -loop 0 "$OUT_GIF"

Usage: sh script.sh target.gif; beware that this script does not check for errors.

I guess you could use this temporarily?

I then realized setting a GIF as wallpaper is just distracting and laggy, so this has no use for me 😞

Zai-Kun commented 2 months ago

Thanks a lot, this should do for now :) Also, what tool did you use to set GIFs as wallpaper? I'm using swww, and I've not experienced any lag, even though my PC's specs are pretty low.

Oughie commented 2 months ago

@Zai-Kun Glad to hear! ^^ I use swww as well and my PC is pretty old too. Running it again now, I noticed it's not actually laggy! It's probably the choppy animation that creates this illusion... Also, there's usually a short pause after each iteration: I'm not sure if it's related to swww or if it's somehow part of the GIF, but I couldn't find any information online on how to get rid of it: That short freeze is quite unsatisfying when it plays in the background.

out

Zai-Kun commented 2 months ago

Ah, i see what you mean. I think it's the GIF, not the tool. I can see a short delay in the GIF before looping again

Oughie commented 2 months ago

Okay, I just found out that the first two frames of the original GIF are identical, which produces the short pause after each loop. 😅

Zai-Kun commented 2 months ago

Ohhh, that explains it 😅

ozwaldorf commented 1 month ago

I was also able to dig up a bit more of a concise script I've used in the past as well, only needs lutgen and imagemagick and will be much faster (due to reusing the LUT for all frames):

#!/usr/bin/env bash
# Script for recoloring gifs with lutgen + im convert

if [ $# -ne 3 ]; then
  echo "usage: $0 <in.gif> <lutgen-palette> <out.gif>"
  exit 1
fi

mkdir -p tmp
convert "$1" -coalesce tmp/%05d.png
lutgen apply tmp/*.png -p "$2"
convert -delay 4 -loop 0 "$2/*.png" -layers Optimize "$3"
rm -r tmp "$2"