Xamarin Android merge audio files with FFMpeg

给你一囗甜甜゛ 提交于 2019-12-07 08:56:59

问题


I am using this binding library for FFMpeg: https://github.com/gperozzo/XamarinAndroidFFmpeg

My goal is to mix two audio files.

String s = "-i " + "test.wav" + " -i " + test2.mp3 + " -filter_complex amix=inputs=2:duration=first " + "result.mp3";

Device.BeginInvokeOnMainThread(async () =>
{
   await FFMpeg.Xamarin.FFmpegLibrary.Run(Forms.Context, s);
});

So I have 2 input files: one is .mp3 and another one is .wav.

I've tried also next commands:

String s= "-i "+ "test.wav" +" -i "+ "test2.mp3" + " -filter_complex [0:0][1:0]concat=n=2:v=0:a=1[out] -map [out] " + "result.mp3";
String s = "-i " + "test.wav" + " -i " + "test2.mp3" + " -filter_complex [0:a][1:a]amerge=inputs=2[aout] -map [aout] -ac 2 " + "result.mp3";

1) Could I mix two different audio formats (in my case .mp3 & .wav) or they should be equivalent? 2) What is the correct command line for the mixing?

Thanks in advance.


回答1:


1) Could I mix two different audio formats (in my case .mp3 & .wav)?

Yes. The input format does not matter because it will be fully decoded to PCM audio before being fed to the filter, but you have to be aware of how the various input channels will be mixed to create the channel layout for the output. Read the documentation on the amerge and amix filters for more info.

2) What is the correct command line for the mixing?

Your command using amerge should work:

ffmpeg -i test.wav -i test2.mp3 -filter_complex "[0:a][1:a]amerge=inputs=2[aout]" -map "[aout]" -ac 2 result.mp3

Or using amix:

ffmpeg -i test.wav -i test2.mp3 -filter_complex "[0:a][1:a]amix=inputs=2:duration=shortest[aout]" -map "[aout]" result.mp3


来源:https://stackoverflow.com/questions/50873573/xamarin-android-merge-audio-files-with-ffmpeg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!