How to add multiple audio files at specific times, on a silence audio file using ffmpeg?

流过昼夜 提交于 2021-02-04 21:33:34

问题


I need to overlay audio files at specific times, on an existing silence.mp3. Something like that:

[----[...audio1...]----------[...audio2...]---------------]

I've tried the following but it doesn't work:

ffmpeg -y -i silence.mp3 -itsoffset 4 -i audio1.mp3 -itsoffset 30 -i audio2.mp3 -c:a copy final.mp3

Any help would be appriciated. Thank you.


回答1:


There are several methods.

adelay, amix

Use the adelay and amix filters:

ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0]adelay=4s:all=1[0a];[1]adelay=30s:all=1[1a];[0a][1a]amix=inputs=2[a]" -map "[a]" output.mp3

Note that the amix filter will reduce volume of the output to prevent clipping. Followup with dynaudnorm or volume filters if desired.

adelay, concat filter

Or adelay and concat filters. This assumes audio1.mp4 is 10 seconds long, and both inputs have the same sample rate and channel layout:

ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0]adelay=4s:all=1[0a];[1]adelay=16s:all=1[1a];[0a][1a]concat=n=2:v=0:a=1[a]" -map "[a]" output.mp3

anullsrc, concat demuxer

Or generate silent files as spacers with the anullsrc filter:

ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t 4 4.mp3
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t 16 16.mp3

Create input.txt:

file '4.mp3'
file 'audio1.mp3'
file '16.mp3'
file 'audio2.mp3'

Then use the concat demuxer:

ffmpeg -f concat -i input.txt -c copy output.mp3


来源:https://stackoverflow.com/questions/60027460/how-to-add-multiple-audio-files-at-specific-times-on-a-silence-audio-file-using

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!