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

Overview

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.
You might also like...
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

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 {

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

Android MoveNet single human pose estimation by ncnn
Android MoveNet single human pose estimation by ncnn

Android MoveNet single human pose estimation by ncnn

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

🐫🐍🍢🅿 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

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

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

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

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

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

Movie Search App - using Flow, Suspend Function, AAC ViewModel, Dagger Hilt and so on.
Movie Search App - using Flow, Suspend Function, AAC ViewModel, Dagger Hilt and so on.

Movie Search App - using Flow, Suspend Function, AAC ViewModel, Dagger Hilt and so on.

FilePicker - Android library to facilitate files picking up process and ability to convert them to request bodies

FilePicker - Android library to facilitate files picking up process and ability to convert them to request bodies

An example concepts of MVVM and Kotlin. Display, Filter & Sort the given restaurants from assets with Jetpack Compose and AAC Android Spinner Dialog Library supported on both Java and Kotlin, Use for single or multi selection of choice
Android Spinner Dialog Library supported on both Java and Kotlin, Use for single or multi selection of choice

SpinnerDialog Android Spinner Dialog Library, Use for single or multi selection of choice Android UI Download To include SpinnerDialog in your project

An Animated Scrolling View for React Native applications, supported on both iOS and Android

react-native-focused-scroll An Animated Scrolling View for React Native applications, supported on both iOS and Android Preview react-native-focus-scr

A seekbar contains two cursor(left and right). Multiple touch supported.
A seekbar contains two cursor(left and right). Multiple touch supported.

RangeSeekbar A seekbar contains two cursor and support multi-touch. RangeSeekbar have left and right cursors, user can move cursor to make fliter. How

This project uses AAC and 3rd parties to present NFT collectibles
This project uses AAC and 3rd parties to present NFT collectibles

My NFT Android app This project uses AAC and 3rd parties to present NFT collectibles AAC(Android Archicture Components) Lifecycle-aware components Vie

Easily adding gaps inside such as Columns and Rows for Jetpack Compose.

Compose Gap Easily adding gaps inside such as Columns and Rows for Jetpack Compose. Inspired by Flutter's Gap. Introduction When it comes to add empty

Comments
  • how import AndroidAudioConverter & IConvertCallback?

    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 ...

    opened by sunny20131314 1
  • Dependency is not resolved

    Dependency is not resolved

    Here are the logs

    Could not find com.github.adrielcafe:ffmpeg-android-java:2a627f6ecd. Required by: project :app > com.github.adrielcafe:AndroidAudioConverter:0.0.8

         Suggestion tried :
         
         1: Added dependency at the app module level and maven URL 'https://jitpack.io'   at the module level.
         2: Added dependency at the app module level and maven URL 'https://jitpack.io'   at the app level.
         
         
         Nothing works. 
         
         Any suggestion how to fix it?
    
    opened by DeepakGrover 0
  • Failed to load FFmpeg lib

    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

    opened by Jomy10 2
  • Permission denied error

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

    opened by kburra73 1
Owner
Adriel Café
Remote Android Developer
Adriel Café
Convert video to GIF. Simple and fast.

Convert video to GIF. Simple and fast.

tasy5kg 24 Nov 26, 2022
[] 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

Google 4.8k Dec 29, 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

Sebastian Annies 2.4k 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

null 377 Jan 2, 2023
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

cine.io 234 Dec 28, 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

David Brodsky 80 Dec 13, 2022
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

Zomato 2.5k Dec 30, 2022
[] 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

AppUnite Sp. z o.o. Spk. 1k 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

Guardian Project 967 Nov 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

Guardian Project 555 Dec 5, 2022