Suppose I have a set of 1000 .gif files, each of different durations, and I want to cycle the hue (hue as in the HLS color space) of each .gif file once over its duration. So, for example, at the beginning, (frame 1) the hue angle should be zero, halfway through (frame n/2) it should be 180 degrees, and at the last frame it should be 360 degrees (frame n). Is this possible to do with ffmpeg? Can you provide an example?

1 Answer 1


Assuming you have bash or similar *nix shell. If you are on Windows, try using Cygwin, or translate the script to PowerShell.

While I haven't tried with ffmpeg, I have came up with a solution that works with ImageMagick, here is the script

#! /bin/bash
framecount=$(($(identify -format "%n\n" $1 | head -1)-1))
startcommand="magick convert $1 "
for frameno in {0..$framecount}
startcommand+="\( -clone $frameno -modulate 100,100,$(echo $framecount $frameno | awk '{ printf("%.2f \n", 200*($2/$1)) }') \) -swap $frameno +delete "
startcommand+="-layers OptimizeFrame huecycled-$(basename $1)"
bash -c $startcommand

Note that it doesn't work with GraphicsMagick. You can use a for loop to run it over all gifs.
for i in *.gif; do huecyclar.sh $i;done

Line 1: Get number of frames. -1 for 0-based indexing
Line 2: Initial command, invoking convert of IM and the file.
For loop: For each frame, add command to clone the frame change hue to 300*(current frame number/number of frame) but keep same brightness and saturation. 300 means 300% of original or 360 degree IM docs on -modulate
Line 8: Add command to optimise frames and set output name to huecycled-<input filename>.
Line 9: Execute the command.
Hope it works.

Here is a demo. First image is a gif consisting 360 frames, all of same image, rose.

Original image

Now this is the output of the script.

Modified version with script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.