1.无原声合并音视频 ffmpeg -i bgm.mp3 -i input.mp4 output.mp4
2.保留原声合并音视频 ffmpeg -i bgm.mp3 -i input.mp4 -filter_complex amix=inputs=2:duration=first:dropout_transition=2 output.mp4
(注意:inputs=输入流数量, duration=决定流的结束,dropout_transition= 输入流结束时,容量重整时间, (longest最长输入时间,shortest最短,first第一个输入持续的时间)) 注意: 音频,视频输入流的命令顺序可能对视频合成有影响(猜测) (更多请查看ffmpeg官方文档) ps:我是看到这位pjqdyd 老哥的回答。
示例JAVA代码如下~
public class MergeVideoMp3 {
private String ffmpegEXE;
public MergeVideoMp3(String ffmpegEXE) {
super();
this.ffmpegEXE = ffmpegEXE;
}
//ffmpeg -i bgm.mp3 -i input.mp4 -t 6 -filter_complex amix=inputs=2 output.mp4
/**
* 注意:inputs=输入流数量, duration=决定流的结束,
* dropout_transition= 输入流结束时,容量重整时间,
* (longest最长输入时间,shortest最短,first第一个输入持续的时间))
* @throws Exception
*/
public void convertor(String videoInputPath, String mp3InputPath,
double seconds, String videoOutput