Convert audio files inside your Android app easily. Supported formats: AAC, MP3, M4A, WMA, WAV and FLAC.

Last update: May 10, 2022

Android Arsenal Release

AndroidAudioConverter

Convert audio files inside your Android app easily. This is a wrapper of FFmpeg-Android-Java lib.

Supported formats:

  • AAC
  • MP3
  • M4A
  • WMA
  • WAV
  • FLAC

Lib size: ~9mb

How To Use

1 - Add this permission into your AndroidManifest.xml and request in Android 6.0+

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

2 - Load the lib inside your Application class

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        AndroidAudioConverter.load(this, new ILoadCallback() {
            @Override
            public void onSuccess() {
                // Great!
            }
            @Override
            public void onFailure(Exception error) {
                // FFmpeg is not supported by device
            }
        });
    }
}

3 - Convert audio files async

File flacFile = new File(Environment.getExternalStorageDirectory(), "my_audio.flac");
IConvertCallback callback = new IConvertCallback() {
    @Override
    public void onSuccess(File convertedFile) {
        // So fast? Love it!
    }
    @Override
    public void onFailure(Exception error) {
        // Oops! Something went wrong
    }
};
AndroidAudioConverter.with(this)
    // Your current audio file
    .setFile(flacFile)  
    
    // Your desired audio format 
    .setFormat(AudioFormat.MP3)
    
    // An callback to know when conversion is finished
    .setCallback(callback)
    
    // Start conversion
    .convert();

Import to your project

Put this into your app/build.gradle:

repositories {
  maven {
    url "https://jitpack.io"
  }
}

dependencies {
  compile 'com.github.adrielcafe:AndroidAudioConverter:0.0.8'
}

Dependencies

Want to RECORD AUDIO into your app?

Take a look at AndroidAudioRecorder! Example of usage here.

License

The MIT License (MIT)

Copyright (c) 2016 Adriel Café

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

GitHub

https://github.com/adrielcafe/AndroidAudioConverter
Comments
  • 1. how import AndroidAudioConverter & IConvertCallback?

    how import AndroidAudioConverter & IConvertCallback?

    if import cafe.adriel.androidaudioconverter; then will get a lot error as follows : MainActivity.java:27: 错误: 找不到符号 import cafe.adriel.androidaudioconverter; ^ 符号: 类 androidaudioconverter 位置: 程序包 cafe.adriel

    AndroidAudioConverter.load(this, new ILoadCallback() { ^ 符号: 类 ILoadCallback 位置: 类 MainActivity ...

    Reviewed by sunny20131314 at 2017-10-31 10:57
  • 2. Failed to load FFmpeg lib

    Hi. I stumbled across this library and it looks very promising.

    I added this to my application:

    public class App extends application {
        @Override
        public void onCreate() {
            AndroidAudioConverter.load(this, new ILoadCallback() {
                @Override
                public void onSuccess() {
                    android.util.Log.d(TAG, "FFmpeg is supported by the device. Succesfully loaded AndroidAudioConverter library.");
                }
                @Override
                public void onFailure(Exception error) {
                    // FFmpeg is not supported by device
                    Log.w(TAG, "FFmpeg is not supported by this device.", error);
                }
            });
        }
    }
    

    And got the following error:

    W/Application: FFmpeg is not supported by this device.
        java.lang.Exception: Failed to loaded FFmpeg lib
            at cafe.adriel.androidaudioconverter.AndroidAudioConverter$1.onFailure(AndroidAudioConverter.java:50)
            at com.github.hiteshsondhi88.libffmpeg.FFmpegLoadLibraryAsyncTask.onPostExecute(FFmpegLoadLibraryAsyncTask.java:54)
            at com.github.hiteshsondhi88.libffmpeg.FFmpegLoadLibraryAsyncTask.onPostExecute(FFmpegLoadLibraryAsyncTask.java:8)
            at android.os.AsyncTask.finish(AsyncTask.java:771)
            at android.os.AsyncTask.access$900(AsyncTask.java:199)
            at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
            at android.os.Handler.dispatchMessage(Handler.java:106)
            at android.os.Looper.loop(Looper.java:223)
            at android.app.ActivityThread.main(ActivityThread.java:7656)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
    

    I then looked into the source code of your project and found that the load method does this:

    try {
                FFmpeg.getInstance(context).loadBinary(new FFmpegLoadBinaryResponseHandler() {
                            @Override
                            public void onStart() {
    
                            }
    
                            @Override
                            public void onSuccess() {
                                loaded = true;
                                callback.onSuccess();
                            }
    
                            @Override
                            public void onFailure() {
                                loaded = false;
                                callback.onFailure(new Exception("Failed to loaded FFmpeg lib"));
                            }
    
                            @Override
                            public void onFinish() {
    
                            }
                        });
            } catch (Exception e){
                loaded = false;
                callback.onFailure(e);
            }
        }
    

    So, I pasted that into my code and replaced catch (exception e) {...} with catch(exception e) {e.printStackTrace();.

    I ran that and got the following error:

    E/FFmpeg: issue in coping binary from assets to data. 
        java.io.FileNotFoundException: x86/ffmpeg
            at android.content.res.AssetManager.nativeOpenAsset(Native Method)
            at android.content.res.AssetManager.open(AssetManager.java:874)
            at android.content.res.AssetManager.open(AssetManager.java:851)
            at com.github.hiteshsondhi88.libffmpeg.FileUtils.copyBinaryFromAssetsToData(FileUtils.java:29)
            at com.github.hiteshsondhi88.libffmpeg.FFmpegLoadLibraryAsyncTask.doInBackground(FFmpegLoadLibraryAsyncTask.java:27)
            at com.github.hiteshsondhi88.libffmpeg.FFmpegLoadLibraryAsyncTask.doInBackground(FFmpegLoadLibraryAsyncTask.java:8)
            at android.os.AsyncTask$3.call(AsyncTask.java:394)
            at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
            at java.lang.Thread.run(Thread.java:923)
    

    So this means that FFmpeg is not installed I guess?

    I looked into the source code of the ffmpeg-android-java and found where the FFmpeg file should be located. I ran:

    System.out.println(this.getFilesDir() + File.separator + "ffmpeg");
    

    And got as output:

    I/System.out: /data/user/0/be.ksa.voetje/files/ffmpeg
    

    I then ran

    System.out.println(new File(this.getFilesDir() + File.separator + "ffmpeg").exists());
    

    And got false, so the file does indeed not exist.

    I'm unfamiliar with the FFmpeg library, so I really have no idea on what I should do now. If you could help me with this one, that would be wonderful.

    Thank you in advance. Jonas

    Reviewed by Jomy10 at 2021-06-15 10:16
  • 3. Permission denied error

    I am using this code to convert my mp3 file in m4a because I want to merge audio and video files and using mp4parser library for this. But I red somewhere that mp4parser only works with m4a audio format. When executing this code I am getting this error "/data/user/0/com.jiviz.m4a: Permission denied".......My audio file is in string format..Log - V/Mux-------: ======/storage/emulated/0/DCIM/Jiviz_2021_02_01_07_15_33.mp4======/data/user/0/com.jiviz.app/files/songs/312mp3

    public String mux(String videoFile, String audioFile) { Log.v("Mux-------","======"+videoFile + "======"+audioFile);

        IConvertCallback callback = new IConvertCallback() {
            @Override
            public void onSuccess(File convertedFile) {
                Toast.makeText(CamRecorderActivity.this, "SUCCESS: " + convertedFile.getPath(), Toast.LENGTH_LONG).show();
            }
            @Override
            public void onFailure(Exception error) {
                Log.v("Conversion-------","======"+error.getMessage());
                Toast.makeText(CamRecorderActivity.this, "ERROR: " + error.getMessage(), Toast.LENGTH_LONG).show();
            }
        };
        Toast.makeText(this, "Converting audio file...", Toast.LENGTH_SHORT).show();
        AndroidAudioConverter.with(this)
                .setFile(new File(audioFile))
                .setFormat(AudioFormat.M4A)
                .setCallback(callback)
                .convert();
    
        Movie video = null;
        try {
            video = new MovieCreator().build(videoFile);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        Movie audio = null;
        try {
            audio = new MovieCreator().build(audioFile);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        } catch (NullPointerException e) {
    
            e.printStackTrace();
            return null;
        }
        int size = audio.getTracks().size();
        Track audioTrack = audio.getTracks().get((size - 1));
        video.addTrack(audioTrack);
    
        Container out = new DefaultMp4Builder().build(video);
    
        File myDirectory = new File(Environment.getExternalStorageDirectory(), "/Jiviz");
        if (!myDirectory.exists()) {
            myDirectory.mkdirs();
        }
        String filePath = myDirectory + "/video" + System.currentTimeMillis() + ".mp4";
        try {
            RandomAccessFile ram = new RandomAccessFile(String.format(filePath), "rw");
            FileChannel fc = ram.getChannel();
            out.writeContainer(fc);
            ram.close();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    

    // File file = new File(filePath); Log.v("Filepath-------","========" +filePath); return filePath; }

    Reviewed by kburra73 at 2021-02-01 13:47
  • 4. Android Q: FFmpeg permission denied

    @adrielcafe With Android 10 the converter is not working anymore because ffmpeg can't be executed. As you are using the ffmpeg library by WritingMinds and they haven't added Android 10 support yet, would it be able to just change the dependency to another ffmpeg library (eg https://github.com/tanersener/mobile-ffmpeg) that supports Android 10?

    Reviewed by tim162 at 2020-11-16 10:09
  • 5. Error 13 Permission Denied

    E/FFmpeg: Exception while trying to run: [Ljava.lang.String;@916ce87
        java.io.IOException: Cannot run program "/data/user/0/com.tuwy/files/ffmpeg": error=13, Permission denied
            at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
            at java.lang.Runtime.exec(Runtime.java:698)
            at java.lang.Runtime.exec(Runtime.java:563)
    

    I am running this app on android 10 with compile and target sdk version 29 I have already provided external storage permission and ' android:requestLegacyExternalStorage="true" ' Can any one suggest some thing ?

    Reviewed by paragwadhwani at 2020-10-29 22:27
[] Easily integrate Camera features into your Android app

Deprecated CameraView is deprecated. No more development will be taking place. Use Jetpack CameraX instead. CameraView This is not an official Google

May 22, 2022
A Java API to read, write and create MP4 files

Build status: Current central released version 1.x branch: Current central released version 2.x branch: Java MP4 Parser A Java API to read, write and

Apr 2, 2021
A mod of the Twitch Android Mobile App adding BetterTTV and FrankerFaceZ emotes
A mod of the Twitch Android Mobile App adding BetterTTV and FrankerFaceZ emotes

A mod of the Twitch Android Mobile App adding BetterTTV and FrankerFaceZ emotes

May 14, 2022
script(s) to build ffmpeg for android, including support for RTMP (and OpenSSL)

android-ffmpeg-with-rtmp This repository contains script(s) to build ffmpeg for android with RTMP (and OpenSSL) support. Instructions Install the Andr

Apr 15, 2022
Script and Instructions for building FFmpeg for Android

FFmpeg-Android Herein lies scripts and instructions for compiling FFmpeg for Android with RTMP support. Much thanks to Chris Ballinger and Liu Feipeng

Mar 21, 2022
AndroidPhotoFilters aims to provide fast, powerful and flexible image processing instrument for creating awesome effects on any image media.
AndroidPhotoFilters aims to provide fast, powerful and flexible image processing instrument for creating awesome effects on any image media.

PhotoFiltersSDK PhotoFiltersSDK aims to provide fast, powerful and flexible image processing instrument for creating awesome effects on any image medi

May 11, 2022
[] FFmpeg build for android random architectures with example jni
[] FFmpeg build for android random architectures with example jni

AndroidFFmpegLibrary This project aims to create working library providing playing video files in android via ffmpeg libraries. With some effort and N

Mar 1, 2021
a system for building custom ffmpeg binaries for Android

This is a new android-ffmpeg project since it seems there were so many different ways of doing it, it was confusing. So here is my clean, easily chan

Apr 12, 2022
Android Java wrapper around ffmpeg command line binary

FFMPEG Library for Android This project is a Java wrapper around an ffmpeg command line binary for use in Android applications. It depends on the andr

Apr 30, 2022
MJPEG video streaming on Android
MJPEG video streaming on Android

ipcam-view Android MJPEG video streaming made simple! A wrapper library around the well known SimpleMjpegView and android-camera-axis projects. If you

May 9, 2022
Android/iOS video player based on FFmpeg n3.4, with MediaCodec, VideoToolbox support.

ijkplayer Platform Build Status Android iOS Video player based on ffplay Download Android: Gradle # required allprojects { repositories {

May 26, 2021
android video player base on ijkplayer
android video player base on ijkplayer

GiraffePlayer NOTE:this project is no longer update please using improved GiraffePlayer2 ,for flutter please visit GPlayer out of the box android vide

Apr 28, 2022
Android MoveNet single human pose estimation by ncnn
Android MoveNet single human pose estimation by ncnn

Android MoveNet single human pose estimation by ncnn

May 20, 2022
Silky - Android application to convert videos from applications such as YouTube, Facebook, Twitter into audio (.mp3)

Silky Español (actualmente la app se encuentra en desarrollo ) Descripcion Aplic

Feb 9, 2022
🐫🐍🍢🅿 Multiplatform Kotlin library to convert strings between various case formats including Camel Case, Snake Case, Pascal Case and Kebab Case

KaseChange Multiplatform Kotlin library to convert strings between various case formats Supported Case Formats SCREAMING_SNAKE_CASE snake_case PascalC

May 14, 2022
An application to convert strings to diffirent formats
An application to convert strings to diffirent formats

Localized An application to convert strings to diffirent formats This app will help developers to convert strings from application in one platform to

Feb 12, 2021
Speech-Text Converter is a simple task that enable the user to convert the speech to text or convert text to speech (by Mic)
Speech-Text Converter is a simple task that enable the user to convert the speech to text or convert text to speech (by Mic)

Speech-Text Converter About Speech-Text Converter is a simple task that enable the user to convert the speech to text or convert text to speech (by Mi

Oct 21, 2021
A Discord audio player that streams audio from the desktop.

Synced A Discord audio player that streams audio from the desktop. Synced runs as a bot that plays audio to your selected Discord server. You can cont

Dec 5, 2021
Autodownload MP3 API With Kotlin

Autodownload MP3 API Overview This project leverages Spring Boot, Google's YouTube API, and youtube-dl to provide an API to download videos and conver

Jan 14, 2022
ICSx⁵ is an Android app to subscribe to remote or local iCalendar files (like time tables of your school/university or event files of your sports team).

ICSx⁵ ICSx⁵ is an Android app to subscribe to remote Webcal feeds / iCalendar files (like time tables of your school/university or event files of your

May 11, 2022