将2个mp3文件与适用于Android的FFmpeg混合使用

将2个mp3文件与适用于Android的FFmpeg混合使用,android,ffmpeg,Android,Ffmpeg,我正在开发类似于卡拉OK的应用程序。我有一个来自android mediarecorder的声音文件(beat)和一个录制的文件(voice)。我试图混合这两个文件,使之成为一个同时播放的文件。我已经建立了writingminds提供的ffmpeg,一切正常。我不熟悉ffmpeg命令,所以搜索得到的命令很少,可以为我完成任务。这是我得到的代码: String files = "-i " + currentFile + " -i " + someFile.getAbsolutePath();

我正在开发类似于卡拉OK的应用程序。我有一个来自android mediarecorder的声音文件(beat)和一个录制的文件(voice)。我试图混合这两个文件,使之成为一个同时播放的文件。我已经建立了writingminds提供的ffmpeg,一切正常。我不熟悉ffmpeg命令,所以搜索得到的命令很少,可以为我完成任务。这是我得到的代码:

  String files = "-i " + currentFile + " -i " + someFile.getAbsolutePath();
            String output = mFileName + "/recorded/test.mp3";
            String cmd = "ffmpeg "+files+
                    " -filter_complex \"aevalsrc=0:d=10[s1];[s1][1:a]concat=n=2:v=0:a=1[ac1];[0:a][ac1]amix[aout]\" -map [aout] -c:a libmp3lame " + output;
但它不起作用。这是我得到的错误:

04-01 12:09:26.598 21300-21300/com.shixels.thankgodrichard.mixer I/fpeg: ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
                                                                           built with gcc 4.8 (GCC)
                                                                           configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
                                                                           libavutil      55. 17.103 / 55. 17.103
                                                                           libavcodec     57. 24.102 / 57. 24.102
                                                                           libavformat    57. 25.100 / 57. 25.100
                                                                           libavdevice    57.  0.101 / 57.  0.101
                                                                           libavfilter     6. 31.100 /  6. 31.100
                                                                           libswscale      4.  0.100 /  4.  0.100
                                                                           libswresample   2.  0.101 /  2.  0.101
                                                                           libpostproc    54.  0.100 / 54.  0.100
                                                                         Output #0, mp3, to 'ffmpeg -i /storage/emulated/0/MyStudio/temps/1491044929409.mp3 -i /storage/emulated/0/temp.mp3 -filter_complex "aevalsrc=0:d=10[s1];[s1][1:a]concat=n=2:v=0:a=1[ac1];[0:a][ac1]amix[aout]" -map [aout] -c:a libmp3lame /storage/emulated/0/recorded/test.mp3':
                                                                         Output file #0 does not contain any stream
04-01 12:09:26.599 21300-21300/com.shixels.thankgodrichard.mixer I/fpeg: finished

我在这里读到一些答案,说这取决于您使用的ffmpeg的版本。我正在使用writingminds为android提供的最新ffmpeg

我不知道android是否适用,但在unix中,您可以使用此命令,也许它可以帮助您:


ffmpeg-filter_complex“amovie=file1.mp3[a0];amovie=file2.mp3[a1];[a0][a1]amix=inputs=2:duration=shortest[aout]”-map[aout]-acodec mp3文件_merged.mp3

它将整个cmd字符串作为输出名称。也许一开始需要避免ffmpeg。尝试过了,但没有成功@Mulvya@Diego这个命令不像问题中的命令那样进行任何连接,在这种情况下,您可以使用
-i input
,而不是
amovie
@LordNeckbeard,正如他所说:“将两个文件混合成一个同时播放的文件”。这不是串联,而是合并。。。是的,您可以使用-i作为输入,然后使用[0:a]和[1:a]在filter complex中使用它们,这两种方法都是有效的。您的命令忽略了原始命令中存在的连接,并且使用
amovie
而不是
-i
是很奇怪的。