1

I have two files - video.mp4 and audio.mp3, and I want to combine them. The final video must have duration of the video.mp4.

I don't know which of these two files is longer so I cannot use the -shortest option.

This is what I have so far:

ffmpeg -y -i video.mp4 -i audio.mp3 -map 0:v -map 1:a -c copy final.mp4

2 Answers 2

5

Use

ffmpeg -y -i video.mp4 -i audio.mp3 -af apad -map 0:v -map 1:a -c:v copy -shortest final.mp4

The apad adds indefinite silence to the audio, so the video will always be the shortest stream.

0
2

The only way I've found is to have a function which first returns the duration of the first file. This is of course bash script, which you can copy/paste into shell, or write a .sh bash script.

function getDuration() {
  ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 video.mp4
}

and then use that function to return the duration, and use that with the -t parameter

ffmpeg -y -i video.mp4 -i audio.mp3 -map 0:v -map 1:a -t $(getDuration) -c copy final.mp4
1
  • Thank you! +1. But I accept @Mulvya 's answer because of his one-line solution.
    – Oleg
    Feb 25, 2016 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .