If I have two GIFs, GIF 1 being 10 seconds long and GIF 2 being 5 seconds long, is there a way to connect them so the final GIF is a total of 15 seconds long?
Would I have to loop through each frame of both the GIFs with imageio.mimread()
and output, once all the frames are read in memory?
Or is there another way by knowing the start and end times and shifting it?
Edit: The solution presented by FirefoxMetzger is extremely Pythonic, ideal if you do not wish to install other software / packages like gifsicle.
import imageio.v3 as iio
import numpy as np
frames = np.vstack([
iio.imread("imageio1.gif"),
iio.imread("imageio2.gif"),
])
# get duration each frame is displayed
iio.imwrite("imageio_combined.gif", frames)
This completes in 15.6 seconds for two GIFs, each containing 100 frames.
However, if runtime is important, I recommend gifsicle:
gifsicle(
sources=["imageio1.gif", "imageio2.gif"], # or just omit it and will use the first source provided.
destination="imageio3.gif",
options=["--optimize=2", "--threads=2", "--no-conserve-memory"]
)
This completes in 4.8 seconds, which is three times as fast.