使用ffmpeg合并两个音频文件

时间:2017-11-24 10:21:42

标签: android ffmpeg android-ffmpeg

我想使用ffmpeg库合并两个mp3文件。但不是succsesfull.Following是我的代码

GeneralUtils.checkForPermissionsMAndAbove(MergerActivity.this, true);
LoadJNI vk = new LoadJNI();
try {
    String workFolder = getApplicationContext().getFilesDir().getAbsolutePath();
    //String[] complexCommand = {"ffmpeg","-i", "/sdcard/videokit/in.mp4"};
    String[] complexCommand = {"ffmpeg -i \"concat: /storage/internalsd/Music/02 Love Dose.mp3| /storage/internalsd/Music/02 Love Dose.mp3\" -acodec copy output.mp3"};

    vk.run(complexCommand , workFolder , getApplicationContext());
    Log.i("test", "ffmpeg4android finished successfully");
} catch (Throwable e) {
    Log.e("test", "vk run exception.", e);
}

错误日志显示在

之后
vk run exception.

com.netcompss.ffmpeg4android.CommandValidationException
    at com.netcompss.loader.LoadJNI.run(LoadJNI.java:39)
    at com.netcompss.loader.LoadJNI.run(LoadJNI.java:55)
    at com.handyaudio.MergerActivity.onMergeButtonClicked(MergerActivity.java:356)
    at com.handyaudio.MergerActivity.onClick(MergerActivity.java:272)
    at android.view.View.performClick(View.java:4446)
    at android.view.View$PerformClick.run(View.java:18437)
    at android.os.Handler.handleCallback(Handler.java:733)

请帮助解决错误。

1 个答案:

答案 0 :(得分:0)

确保首先拥有权限

试试这个 -

ffmpeg -filter_complex "amovie=file1.mp3 [a0]; amovie=file2.mp3 [a1]; [a0][a1] amix=inputs=2:duration=shortest [aout]" -map [aout] -acodec mp3 file_merged.mp3

修改1:

concat协议是这样的:ffmpeg -i 'concat:input1|input2 -codec copy output

我认为您出错的地方是,在您的文件名中,在填写文件名之前加上space,即02 LoveDose.mp3