How to insert an audio file into a video with ffmpeg ?

Vlad2012

Elite Member
Joined
Dec 28, 2012
Messages
1,825
Reaction score
723
I need to randomly insert an audio file (audio.mp3) into a .mp4 video with FFmpeg but I can't! The audio.mp3 file should be inserted into the video by cutting its sound and that anywhere in the video... Do you have an idea of the command to perform ?
 
its sound and that anywhere in the video
I don't understand what you mean but it's pretty easy
Code:
ffmpeg \
    -i video1.mp4 -i audio1.mp3 \
    -c:v copy \
    -map 0:v -map 1:a \
    -y output.mp4

You maybe need to cut the audio in order to fit the video lenght?
get the video duration
Code:
ffprobe -i <file> -show_entries format=duration -v quiet -of csv="p=0"
and maybe trim it with sox
Code:
sox input output trim <seconds given by ffprobe>

No rocket science...
 
Back
Top