DEV Community

Dmitry Romanoff
Dmitry Romanoff

Posted on

How to create video file from images and music track?

Let's assume we have 10 images:

image1.jpg, image2.jpg, ... , image10.jpg

and music track

music.mp3

In my blog, I'll demonstrate how to create a video file from images and a music track.

Also, I want to implement smooth transition between the images.

You can use my blog post to create slide presentations or just cool video files.

I will use the FFmpeg tool.

FFmpeg is a free and open-source software project consisting of a large suite of libraries and programs for handling video, audio, and other multimedia files and streams. It is widely used in video production, streaming services, and other multimedia applications.

FFmpeg can perform a wide range of functions such as format conversion, codec transcoding, audio and video scaling, and video filtering, among others. It can handle a variety of multimedia file formats and protocols, making it a valuable tool for developers and content creators alike.

FFmpeg is a command-line tool, meaning it can be used via the terminal or command prompt, and can be integrated into other applications and workflows. It is also available for multiple operating systems, including Linux, Mac OS, and Windows.

 ffmpeg \
-loop 1 -t 5 -i image1.jpg \
-loop 1 -t 5 -i image2.jpg \
-loop 1 -t 5 -i image3.jpg \
-loop 1 -t 5 -i image4.jpg \
-loop 1 -t 5 -i image5.jpg \
-loop 1 -t 5 -i image6.jpg \
-loop 1 -t 5 -i image7.jpg \
-loop 1 -t 5 -i image8.jpg \
-loop 1 -t 5 -i image9.jpg \
-loop 1 -t 5 -i image10.jpg \
-i music.mp3 \
-filter_complex \
"[0:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=out:st=4:d=1[v0]; \
 [1:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1]; \
 [2:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2]; \
 [3:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v3]; \
 [4:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v4]; \
 [5:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v5]; \
 [6:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v6]; \
 [7:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v7]; \
 [8:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v8]; \
 [9:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v9]; \
 [v0][v1][v2][v3][v4][v5][v6][v7][v8][v9]concat=n=10:v=1:a=0,format=yuv420p[v]" -map "[v]" -map 10:a -shortest -movflags +faststart out.mp4
Enter fullscreen mode Exit fullscreen mode

Top comments (0)