<p>Assuming you have bash or similar *nix shell. If you are on Windows, try using Cygwin, or translate the script to PowerShell.</p>
<p>While I haven't tried with ffmpeg, I have came up with a solution that works with ImageMagick, here is the script</p>
<pre><code>#! /bin/bash
framecount=$(($(identify -format &quot;%n\n&quot; $1 | head -1)-1))
startcommand=&quot;magick convert $1 &quot;
for frameno in {0..$framecount}
do
startcommand+=&quot;\( -clone $frameno -modulate 100,100,$(echo $framecount $frameno | awk '{ printf(&quot;%.2f \n&quot;, 200*($2/$1)) }') \) -swap $frameno +delete &quot;
done
startcommand+=&quot;-layers OptimizeFrame huecycled-$(basename $1)&quot;
bash -c $startcommand
</code></pre>
<p>Note that it doesn't work with GraphicsMagick. You can use a for loop to run it over all gifs.<br />
<code>for i in *.gif; do huecyclar.sh $i;done</code></p>
<p><strong>Explanation:</strong><br />
Line 1: Get number of frames. -1 for 0-based indexing<br />
Line 2: Initial command, invoking convert of IM and the file.<br />
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 <a href="https://imagemagick.org/script/command-line-options.php#modulate" rel="nofollow noreferrer">IM docs on <code>-modulate</code></a><br />
Line 8: Add command to optimise frames and set output name to huecycled-&lt;input filename&gt;.<br />
Line 9: Execute the command.<br />
Hope it works.</p>
<p>Here is a demo. First image is a gif consisting 360 frames, all of same image, rose.</p>
<p><a href="https://i.sstatic.net/BwMuf.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BwMuf.gif" alt="Original image" /></a></p>
<p>Now this is the output of the script.</p>
<p><a href="https://i.sstatic.net/WkLiB.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/WkLiB.gif" alt="Modified version with script" /></a></p>

CC BY-SA 4.0
2021-08-07T05:35:15.923Z
2021-08-08T15:36:19.990Z
2021-08-08T15:36:19.990Z
Abdullah Ibn Fulan
<p>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?</p>

<ffmpeg><animation><hls>
Hue Cycle .gif files with ffmpeg as percentage of duration
EllipticalInitial
# Hue Cycle .gif files with ffmpeg as percentage of duration

(Asked by: username_0 on 2021-07-29)

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?

**Tags:** ffmpeg, animation, hls


---

## 1 answers

### Answer by username_1 on 2021-08-07. Score: 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}
do
startcommand+="\( -clone $frameno -modulate 100,100,$(echo $framecount $frameno | awk '{ printf("%.2f \n", 200*($2/$1)) }') \) -swap $frameno +delete "
done
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
Explanation:
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-.
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.

Now this is the output of the script.


---

