0

If I understand correctly you can't use ffmpeg on android.

How can I convert either mp4 or webm to mp3 in Xamarin.Android on Android 10 and higher without using ffmpeg or any external servers?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 1
    Last I checked mp3 is audio only, is that what you want? Probably should clarify what exactly you want. Also, post what you have tried. – mxmissile Sep 07 '22 at 20:50
  • You [can use ffmpeg](https://stackoverflow.com/questions/4725773/ffmpeg-on-android) on Android – OneCricketeer Sep 07 '22 at 20:54
  • @mxmissile Yes, I just want to extract the audio. For things I have tried, there's not much because I wasn't able to find anything useful on the internet. Mostly old posts that are long deprecated. – Peťo Build Sep 07 '22 at 21:16
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 08 '22 at 10:43

1 Answers1

0

Okay, so there indeed is FFmpeg for Android.

For anyone in the same situation:
GitHub: https://github.com/Laerdal/Laerdal.FFmpeg.Android
NuGet: https://www.nuget.org/packages/Laerdal.FFmpeg.Android.Full/
On GitHub there are also links to Xamarin.Forms or Xamarin.IOS and non-full builds.

Usage:
After adding package add to top of the file: using Laerdal.FFmpeg.Android;
Then: FFmpeg.Execute(string comand)

It essentially works the same as FFmpeg in CLI.
FFmpeg.Execute($"-i {source_file} {output_path}/filename.mp3");
Would be same as ffmpeg -i input_file output_file in CLI.

Code example of converting any file type to .mp3 and handling status codes (works for .webm and .mp4, tested on Android 10):

int status = FFmpeg.Execute($"-i {source_file} {new_path}/filename.mp3");
if(status == 0)
{
    Console.WriteLine("Success");
}
else
{
    Console.WriteLine($"FFmpeg failed with status code {status}");
}

If you have other questions about FFmpeg please refer to FFmpeg Documentation https://www.ffmpeg.org/documentation.html