How to overlap and merge multiple audio files using ffmpeg?

北城以北 提交于 2019-12-31 05:36:09

问题


I am trying to merge multiple audio files into a single file but instead of concatenating which I can do using the following command:

ffmpeg -v debug -i file1.wav -i file2.wav -i file3.wav -filter_complex [0:0]concat=n=3:v=0:a=1[out] -map [out] output.wav

Though this command works fine for concatenating, I want to overlap let's say the last 100ms of the end of the first file and 100ms of the start of the next file.

I am now trying to use 'acrossfade' filter that ffmpeg provides but I am not having any success with it.

ffmpeg -v debug -i file1.wav -i file2.wav -i file3.wav -filter_complex [0:a]acrossfade=d=0.100:c1=exp:c2=exp,[1:a]acrossfade=d=0.100:c1=exp:c2=exp,[2:a]acrossfade=d=0.100:c1=exp:c2=exp

This is what I have come up till now, but does not work as it throws 'Buffer is too short (n=0) for frame_length=1' error.

The documentation is not very helpful, does anyone have any idea what can be done?

Thanks in advance!


回答1:


acrossfade is meant to create a transition between two inputs. So, each pair of inputs has to have acrossfade applied with the result being used as an input for the next acrossfade.

ffmpeg -v debug -i file1.wav -i file2.wav -i file3.wav -filter_complex "[0:a][1:a]acrossfade=d=0.100:c1=exp:c2=exp[a01];[a01][2:a]acrossfade=d=0.100:c1=exp:c2=exp" out.wav

Edit: your inputs are 16000 Hz, and your crossfade duration is 0.1s (!), which is less than 2 audio frames at the input sampling rate. Default frame size is 1024 samples. So, frame size needs to be lowered.

ffmpeg -v debug -i file1.wav -i file2.wav -i file3.wav -filter_complex "[0:a]asetnsamples=256[0a];[1:a]asetnsamples=256[1a];[2:a]asetnsamples=256[2a];[0a][1a]acrossfade=d=0.100:c1=exp:c2=exp[a01];[a01][2a]acrossfade=d=0.100:c1=exp:c2=exp" out.wav



来源:https://stackoverflow.com/questions/55097002/how-to-overlap-and-merge-multiple-audio-files-using-ffmpeg

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