简体   繁体   中英

ffmpeg mix audio at specific time

I want to mix 2 audio files together - one file has a length of 2 mins and the other is a 10 second sound. I want both files to mix so both sounds can still be heard. I want this 10 second clip to come in exactly at 30 seconds for the 10 seconds so it will end at 40 seconds.

I know how to mix 2 audio files together using ffmpeg

ffmpeg -i input.mp3 -i input2.mp3 -filter_complex amerge -c:a libmp3lame -q:a 4 output.mp3

However, I do not know how to start this 10 second sound at a specific time.

since posting this i have found a solution to this problem - i want to share it for other people to use as i spent a lot of time looking for this.

create a blank audio file longer than the longest clip.

ffmpeg -f lavfi -i anullsrc=r=44100:cl=mono -t <seconds> -q:a 9 -acodec libmp3lame <blank audio>

from here then you need to add the 10 second clip at the time you want to the blank audio file.

ffmpeg -i <blank audio> -i < audio file 2> -filter_complex "aevalsrc=0:d= <time> [s1];[s1][1:a]concat=n=2:v=0:a=1[aout]" -c:v copy -map 0:v -map [aout] <output file>

from here then you overlay this now longest clip to the original longer clip

ffmpeg -i <output from silent and short clip> -i <original long clip> -filter_complex "amix=inputs=2:duration=longest:dropout_transition=0, volume=2" <output audio file>

My audio sample rate is 8000. I used the following command without synthetic audio to insert 3 audio files at specific times. Please note that delays in seconds have to be integers. For a precise position, you can use 'S' (Sample) instead of 's' (second) to define delays.

ffmpeg -y -i earth.mp4 -i 1.wav -i 2.wav -i 3.wav -filter_complex "[1]adelay=delays=5s:all=1[r1]; [2]adelay=delays=8000S:all=1[r2]; [3]adelay=delays=15s:all=1[r3]; [r1][r2][r3]amix=inputs=3[a]"  -map 0:v -map "[a]" -codec:v copy output.mp4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM