ajay dhadhal
ajay dhadhal

Reputation: 306

Merge two audio file using ffmpeg

I want to merge Two mp3 file using ffmpeg library.but not succsesfull.Following is my code

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);
}

The error log display following

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)

Please help to solve error.

Upvotes: 1

Views: 3917

Answers (1)

Shivansh Jagga
Shivansh Jagga

Reputation: 1881

Make sure you have permissions first.

Try this out -

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

Edit 1 :

The concat protocol is this : ffmpeg -i 'concat:input1|input2 -codec copy output

I think where you are going wrong is that in your file names, you put a space before completing the file name, i.e, 02 LoveDose.mp3

Upvotes: 1

Related Questions