ffmpeg 库的地址
https://github.com/tanersener/mobile-ffmpeg
在10000的位置插入 test2.mp3 20000毫秒插入test3.mp3 30000毫秒的位置插入test4.mp3 最后生成 /apptend.mp3
ffmpeg -y -i /storage/emulated/0/1/audio/test1.mp3 -i /storage/emulated/0/1/audio/test2.mp3 -i /storage/emulated/0/1/audio/test3.mp3 -i /storage/emulated/0/1/audio/test4.mp3 -filter_complex "[1]adelay=10000|10000[1_]; [2]adelay=20000|20000[2_]; [3]adelay=30000|30000[3_]; [0][1_][2_][3_]amix=4" /storage/emulated/0/1/audio/apptend.mp3
//音频和视屏混音
ffmpeg -i /storage/emulated/0/1/video/1.mp4 -i /storage/emulated/0/1/audio/apptend.mp3 -vcodec copy -filter_complex amix=inputs=2:duration=first -strict -2 /storage/emulated/0/1/output/mix.mp4
/**
* key 录音音频地址
* value 配音的截止时长 多少毫秒
*/
public String getmixAudiocommandLine(LinkedHashMap<String,Integer> para, String outputAudioPath){
String preCommand = "-y";
String lastCommand=" -filter_complex \"";
int index=0;
String tip="_";
for (Map.Entry<String, Integer> entry : para.entrySet()) {
index++;
String audioAddress = entry.getKey();
preCommand+=" -i "+audioAddress;
int audioLength = entry.getValue();
if (index==para.entrySet().size()){
for (int j=0;j<para.entrySet().size();j++){
if (j==0){
lastCommand+="[0]";
}else if (j==para.entrySet().size()-1){
lastCommand+="["+j+tip+"]"+"amix="+para.entrySet().size()+"\" ";
}else {
lastCommand+="["+j+tip+"]";
}
}
}else {
lastCommand+="["+index+"]adelay="+audioLength+"|"+audioLength+"["+index+tip+"]; ";
}
}
String commandLine = preCommand+lastCommand+outputAudioPath;
Log.e("commandLine---",commandLine);
return commandLine;
}