FFmpeg Creating video from images

FFmpeg is a versatile multimedia processing tool that provides developers with the capability to create videos from a sequence of images. This process is commonly used for generating time-lapse videos, animations, or slideshows. In this comprehensive guide, we will explore how to use FFmpeg to create a video from a series of images.

  1. Installing FFmpeg:
    Before you begin, ensure that you have FFmpeg installed on your system. You can download the latest version from the official website (https://ffmpeg.org/download.html) or use package managers such as Homebrew on macOS or APT on Linux.
  2. Prepare Your Images:
    Organize the images you want to convert into a video in a single directory. Ensure that the images are named in a sequential order (e.g., image1.jpg, image2.jpg, etc.) for a smooth transition in the video.
  3. Navigate to the Image Directory:
    Open a terminal or command prompt and navigate to the directory containing your images using the cd command. For example:
   cd /path/to/image/directory
  1. Execute FFmpeg Command:
    Use the following FFmpeg command to create a video from the images:
   ffmpeg -framerate 30 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p output.mp4

Breakdown of the command:

  • -framerate 30: Sets the frame rate of the output video to 30 frames per second. Adjust this value based on your preference.
  • -pattern_type glob: Informs FFmpeg to use glob pattern matching for input files.
  • -i '*.jpg': Specifies the input image files using the glob pattern. Adjust the pattern if your images have a different extension.
  • -c:v libx264: Selects the H.264 video codec for compression.
  • -pix_fmt yuv420p: Sets the pixel format to yuv420p, which is widely compatible.
  • output.mp4: Defines the name of the output video file. Change this as needed.
  1. Adjusting Parameters:
  • Frame Rate (-framerate): Modify the frame rate to control the speed of the video. A higher frame rate results in a smoother but larger video file.
  • Video Codec (-c:v): FFmpeg supports various video codecs. Choose one based on your requirements and compatibility.
  • Pixel Format (-pix_fmt): Ensure compatibility with most devices and platforms by using the yuv420p pixel format.
  1. Executing the Command:
    Press Enter to execute the FFmpeg command. FFmpeg will process the images and create a video with the specified parameters. The progress will be displayed in the terminal.
  2. Viewing the Output:
    Once the process is complete, navigate to the output directory and open the generated video file (output.mp4) using your preferred media player to preview the result.
  3. Customization and Additional Options:
    Explore FFmpeg’s extensive documentation for advanced options, such as adding audio, adjusting video quality, or applying filters. Customizing the command allows you to achieve specific effects or meet particular requirements.

FFmpeg is a versatile multimedia processing tool that provides developers with the capability to create videos from a sequence of images. This process is commonly used for generating time-lapse videos, animations, or slideshows. In this comprehensive guide, we will explore how to use FFmpeg to create a video from a series of images.

  1. Installing FFmpeg:
    Before you begin, ensure that you have FFmpeg installed on your system. You can download the latest version from the official website (https://ffmpeg.org/download.html) or use package managers such as Homebrew on macOS or APT on Linux.
  2. Prepare Your Images:
    Organize the images you want to convert into a video in a single directory. Ensure that the images are named in a sequential order (e.g., image1.jpg, image2.jpg, etc.) for a smooth transition in the video.
  3. Navigate to the Image Directory:
    Open a terminal or command prompt and navigate to the directory containing your images using the cd command. For example:
   cd /path/to/image/directory
  1. Execute FFmpeg Command:
    Use the following FFmpeg command to create a video from the images:
   ffmpeg -framerate 30 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p output.mp4

Breakdown of the command:

  • -framerate 30: Sets the frame rate of the output video to 30 frames per second. Adjust this value based on your preference.
  • -pattern_type glob: Informs FFmpeg to use glob pattern matching for input files.
  • -i '*.jpg': Specifies the input image files using the glob pattern. Adjust the pattern if your images have a different extension.
  • -c:v libx264: Selects the H.264 video codec for compression.
  • -pix_fmt yuv420p: Sets the pixel format to yuv420p, which is widely compatible.
  • output.mp4: Defines the name of the output video file. Change this as needed.
  1. Adjusting Parameters:
  • Frame Rate (-framerate): Modify the frame rate to control the speed of the video. A higher frame rate results in a smoother but larger video file.
  • Video Codec (-c:v): FFmpeg supports various video codecs. Choose one based on your requirements and compatibility.
  • Pixel Format (-pix_fmt): Ensure compatibility with most devices and platforms by using the yuv420p pixel format.
  1. Executing the Command:
    Press Enter to execute the FFmpeg command. FFmpeg will process the images and create a video with the specified parameters. The progress will be displayed in the terminal.
  2. Viewing the Output:
    Once the process is complete, navigate to the output directory and open the generated video file (output.mp4) using your preferred media player to preview the result.
  3. Customization and Additional Options:
    Explore FFmpeg’s extensive documentation for advanced options, such as adding audio, adjusting video quality, or applying filters. Customizing the command allows you to achieve specific effects or meet particular requirements.

FFmpeg Video from one image

To convert a still image to a video is easy and can be used to create slideshows, where short videos from images (with added text) are joined together, joining videos is described in the chapter 23. For example to create a 10-second video from the photo.jpg file, we include a -loop boolean option with a value true or 1 like in the command:

ffmpeg -loop 1 -i photo.jpg -t 10 photo.mp4

FFmpeg Video from many images

To create a video from multiple images, their filenames must end with a number, where these numbers correspond with the sequence in which the images will be encoded to the video file. In this case the media format is specified before the input and it is an image2 format. For example, from 100 images named img1.jpg, img2.jpg, …, img100.jpg can be created a 4-second video with 25 fps frame rate using the command

ffmpeg -f image2 -i img%d.jpg -r 25 video.mp4

If the image numbers start with zeros, for example img001.jpg, img002.jpg, etc. to provide the same filename length, then the command is

ffmpeg -f image2 -i img%3d.jpg -r 25 video.mp4

Conclusion:
Creating videos from images using FFmpeg is a straightforward process that offers flexibility and control over the final output. By following this step-by-step guide, you can generate videos from a sequence of images and explore additional features to enhance the visual appeal of your videos.

Leave a Comment