2024-09-30 Web Development

Create a GIF file from jpegs

By O Wolfson

To create a GIF file running at 5 frames per second from a series of JPEG images named image001.jpg, image002.jpg, image003.jpg, etc., using ffmpeg, you can use the following command:

sh
ffmpeg -framerate 5 -i image%03d.jpg -vf "scale=iw:-1" output.gif

Here's a step-by-step explanation of the command:

  1. -framerate 5: This sets the frame rate to 5 frames per second.
  2. -i image%03d.jpg: This specifies the input files. The image%03d.jpg pattern means that the input files are named image001.jpg, image002.jpg, image003.jpg, and so on. %03d is a placeholder for a 3-digit number, ensuring the correct sequence.
  3. -vf "scale=iw:-1": This applies a video filter to scale the images. iw is the input width, and -1 maintains the aspect ratio of the images.
  4. output.gif: This is the name of the output GIF file.

Run this command in the terminal or command prompt where your images are located. This will generate the GIF with the specified frame rate and maintain the aspect ratio of the images.