Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

FFMPEG Command to Create MP4 Video From Multiple Images in Command Line

Posted on March 17, 2023

 

To create a video from multiple images, each appearing for a certain duration, and add a background audio file that repeats or loops, you can use the following ffmpeg command:

 

 

ffmpeg -framerate 1/5 -i input/image%d.jpg -vf scale=960:540 -c:v libx264 -pix_fmt yuv420p -r 30 output.mp4

You can use the ffmpeg command to create a video from images with each image appearing for a specified number of seconds using the image2 and concat demuxers.

 

Here is an example command that will create a video from images in the input/ directory with each image appearing for 5 seconds:

This command specifies the following:

 

  • -f image2: use the image2 demuxer to read in the images.

 

  • -framerate 1/5: set the input framerate to 1/5, which means each image will be displayed for 5 seconds.

 

  • -i input/image%d.jpg: specify the input images, with %d indicating the image number.

 

  • -c:v libx264: encode the video using the H.264 codec.

 

  • -pix_fmt yuv420p: set the pixel format to YUV 4:2:0, which is a widely supported format.

 

  • -r 30: set the output framerate to 30 fps.

 

  • output.mp4: specify the output file name and format.

 

 

Adjust the -framerate option to control the duration of each image. For example, if you want each image to appear for 3 seconds, you can set -framerate 1/3.

 

 

Here’s an example directory structure for the images you want to use in the ffmpeg command:

 

 

 

 

In this structure, all the input images are stored in the input/ directory. The image files should be named in sequential order, such as image1.jpg, image2.jpg, image3.jpg, and so on.

 

 

Note that you can use other image file formats supported by ffmpeg, such as PNG or BMP. Just make sure that the file extensions match the actual file formats of your images.

 

 

Also, make sure that you run the ffmpeg command from the same directory where the input images are located, or use a relative or absolute path to specify the input image directory.

 

 

In this example, the scale filter is used to resize the input images to a width of 960 pixels and a proportional height of 540 pixels. Note that 960 is an even number, so the resulting video should not trigger the “width not divisible by 2” error.

 

 

Adjust the 960 value to match the desired even width for your video. Also, note that resizing the images may affect the overall quality of the video, so it’s best to use the original input images whenever possible.

Recent Posts

  • FFMPEG Command to Create MP4 Video From Multiple Images in Command Line
  • How to Add Let’s Encrypt SSL Certificate to Domain Using Certbot in Nginx
  • Node.js Fluent-FFMPEG Audio Pitch & Speed Changer With Live Preview in Browser Using Express
  • React.js react-awesome-modal Example to Show Popup Modal With Animation in Browser Using Javascript
  • Node.js Express Server Side Form Validation With Custom Error Messages Using express-validator Library in Javascript
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme