matteoh
matteoh

Reputation: 3630

Extract raw audio frames from OGG music file with Android NDK

In my Android app, I would like to be able to process audio on the fly from an OGG file by extracting audio samples, process them and redirect them to the audio output.

I know how to make the last 2 steps using Android NDK, but I don't know how to extract audio samples to get them in an array of floats or shorts.

I tried to make this code work that, apparently, can extract raw audio samples on the fly.

The problem is: I don't manage to add FFMpeg in my project. I tried many tutorials (like this one), but it seems pretty difficult since I work on Windows. So after a while, I found Prebuild FFMpeg for Android, that seems interesting since it's available for armeabi-v7a, arm64-v8a, x86 and x86_64 architectures, but again, I don't understand how to add it in my project.

I also took a look at libogg, libvorbis and vorbisfile, but I have no idea how to add them in my project.

So, does anyone have a working example on how to extract audio samples from an OGG file on the fly?

Thanks for your help.

Upvotes: 1

Views: 490

Answers (1)

matteoh
matteoh

Reputation: 3630

Here is how I finally managed to proceed:

  1. Here is a very detailed tutorial that explains clearly how to compile FFMpeg for Android (please take a close look at the comments): https://www.youtube.com/watch?v=2OGbamEjYhc
  2. Then, here is a good tutorial that explains how to implement the FFMpeg library in an Android project (starting from "Integration of pre-built C/C++ libraries to an Android project"): https://proandroiddev.com/android-ndk-how-to-integrate-pre-built-libraries-in-case-of-the-ffmpeg-7ff24551a0f
  3. Here is how I finally managed to extract audio samples from an audio file using FFMpeg: https://gist.github.com/mregnauld/2538d98308ad57eb75cfcd36aab5099a

For the step #2, you'll just have to make minor updates so you can target the following ABIs:

  • armeabi-v7a
  • arm64-v8a
  • x86
  • x86_64

Hope this helps.

Upvotes: 1

Related Questions