Attach Images and Audio to Video

I have many images of different sizes (for example, 1024x768 and 900x942) and an audio file (audio.mp3) in 30 seconds, and I need to create a video from them.

I'm trying to use now: result% d.png (1 to 4) and audio.mp3

ffmpeg -y -i result%d.png -i audio.mp3 -r 30 -b 2500k -vframes 900 -acodec libvo_aacenc -ab 160k video.mp4 

Video.mp4 video has 30 seconds, but the first 3 images are displayed very quickly when the last image remains until the end of the sound.

Each image should be displayed at the same time until the end of the sound. Does anyone know how to do this?

The number of images will sometimes change.

+6
source share
3 answers

FFMPEG Version: 3.2.1-1

UBUNTU 04.16.1

Suppose you have an mp3 file called wow.mp3. In this case, the following command will get the mp3 duration in seconds.

 ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 wow.mp3 

Once you have the duration in seconds (imagine I got 11.36 seconds). Now that I have 3 images, I want to run each image for (11.36 / 3 = 3.79), then please use the following:

 ffmpeg -y -framerate 1/3.79 -start_number 1 -i ./swissGenevaLake_%d.jpg -i ./akib.mp3 -c:v libx264 -r 25 -pix_fmt yuv420p -c:a aac -strict experimental -shortest output.mp4 

Pictured here. / swissGenevaLake _1.jpg,. / swissGenevaLake_2.jpg, and. / swissGenevaLake_3.jpg.

Fragment 1 / 3.784 means that each image is executed within 3,784 seconds.

-start_number 1 means starts with image number one, which means. / swissGenevaLake _1.jpg

-c: v libx264: H.264 video codec

-r 25: video output frame rate 25

-pix_fmt yuv420p: output video stream format.

-c: a aac: encode audio using aac

-shortest: end the video as soon as the sound is completed.

output.mp4: output file name

Disclaimer: I have not tested merging images of several sizes.

References:

https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images

https://trac.ffmpeg.org/wiki/Encode/AAC

http://trac.ffmpeg.org/wiki/FFprobeTips

+3
source

To create video = n no image + audio

Step 1)

You will create a video of these images as

 Process proc = Runtime.getRuntime().exec(ffmpeg + " -y -r "+duration +" -i " + imagePath + " -c:v libx264 -r 15 -pix_fmt yuv420p -vf fps=90 " + imageVideoPath); InputStream stderr = proc.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { //System.out.println(line); } int exitVal = proc.waitFor(); proc.destroy(); 

Where duration = No image / Sound duration For 1 second you want how many images

Step 2)

  Process proc4VideoAudio = Runtime.getRuntime().exec(ffmpeg +" -i " + imageVideoPath + " -i "+ audioPath + " -map 0:0 -map 1:0 " + videoPath); InputStream stderr1 = proc4VideoAudio.getErrorStream(); InputStreamReader isr1 = new InputStreamReader(stderr1); BufferedReader br1 = new BufferedReader(isr1); String line1 = null; while ((line1 = br1.readLine()) != null) { //System.out.println(line1); } int exitVal1 = proc4VideoAudio.waitFor(); proc4VideoAudio.destroy(); 

Both steps 1 and 2 can be performed in sequence. If you want to do this manually, then only run Runtime.getTime.exec(..)

The code below is to make it synchronized.

** Also pay attention to the FFMPEG instruction for creating video one step from images and audio, gives you the same problem as you, and if not, the solution is static to correct the number of images for a given audio file.

These imagePath, VideoPath, audioPath are all lines

+1
source

This should help: http://ffmpeg.org/trac/ffmpeg/wiki/Create%20a%20video%20slideshow%20from%20images

Using -r , you can set the number of seconds that you want each image to be displayed.

0
source

All Articles