Is there a way to decode an AMR audio file in Android and have access to the raw audio data? MediaCodec is only available for API 16 and above. I need something that will work on Android 2.2 and above.
I think there's no native API in 2.X platforms for doing this. You can use ffmpeg binaries in your application instead.
With a quick search I found this precompiled version of ffmpeg for Android 2.2.
You can place the executable it in your application raw resources folder and use Runtime.getRuntime().exec() to execute it.
To convert an AMR file to WAV with ffmpeg you can do something like this:
ffmpeg -i file.amr file.wav
and to convert a wav to raw PCM you can do the following: (taken from here)
ffmpeg -i file.wav -f s16le -acodec pcm_s16le file.pcm
Related
anyone know how to merge a single image with already selected video in android through any library because i cannot find any solution for this issue i have checked some libraries such as FFmpeg and OpenCV but they seem not to help in my case
Thanks!
ffmpeg can definitely overlay an image over a video if this is what you are looking for.
The documentation provides some some examples - they key option is 'filter-complex':
ffmpeg -i video.mkv -i image.png -filter_complex '[0:v][1:v]overlay[out]' -map
'[out]' out.mkv
See here for the official documentation: https://ffmpeg.org/ffmpeg.html and look at '-filter_complex filtergraph (global)'
ffmpeg is designed as a command line tool, but there exist 'wrapper' projects to allow it be used from an Android app. A well supported example is below but others exist also:
https://github.com/WritingMinds/ffmpeg-android-java
The above includes a sample APK so you can try out the ffmpeg command you need with that to ensure it works before adding to your own project.
I am using Android-FFmpeg .aar file fromAndroid-FFmpeg for loading FFmpeg binaries. Is there any way to link the ffmpeg command line output from that module to exoplayer so that it streams the video with out saving the video. Otherwise should i have to develop some FFmpeg decoder to decode video as an extension to exoplayer using Media Codec Renderer?
We know ffmpeg to convert an mp3 to wav, as in the following command:
ffmpeg -i testlong.mp3 -f wav output.wav
However, I would like to know how to achieve the above command line function with C language.
ps: I want to achieve in the Android devices, convert audio formats,
in addition to ffmpeg, I do not know what a good solution.
Thanks!
Compile ffmpeg for android
Below link has some way to perform that.
https://trac.ffmpeg.org/wiki/CompilationGuide/Android
Now you can put all code of ffmpeg in JNI folder and use its methods in c to Java methods and use it in java activity.
Other method is just cross compile ffmpeg and install it in android.
then using system() call in java use that ffmpeg -i testlong.mp3 -f wav output.wav
One way is to compile the entire ffmpeg.c file into your application and then generate the command line within your application, then pass it on into ffmpeg's main() (that you will probably rename). The other way is to study the its source code, online tutorials, ... and write your own converter based on that.
I want to mix(not concatenate) 2 audio files in android. For ex : first file has audio and second file has voice. I want to mix these 2 files and generate output file who have music and voice playing simultaneously.
I know about ffmpeg. i have compile ffmpeg using android NDK. but i do not know how to run ffmpeg command using android
other way instead of ffmpeg is also ok.
Thanks a lot..
Check out those resources for Audio/Video tasks with FFmpeg for Android:
Tutorial to compile FFmpeg for Android:
http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/
FFMpeg API examples:
http://ffmpeg.org/doxygen/trunk/examples.html
Also if you search github for FFmpeg and Android you'll find a lot of resources.
Hope this helps,
Cheers.
I am trying to create a 3gp video file by combining an mp3 audio clip and an image for my android application. That is:
mp3 + image = 3gp video clip.
I did so much research on this but found that help available was limited.
Please let me know how to do this.
If you are looking to do that outside of your application then check out this post which gives ffmpeg command that can be used to achieve the same.
Also ffmpeg can also be compiled for android and used using the JNI as discussed in this post.
copying the best answer for quick reference:
Here are the steps I went through in getting ffmpeg to work on Android:
Build static libraries of ffmpeg for Android. This was achieved by
building olvaffe's ffmpeg android port (libffmpeg) using the Android
Build System. Simply place the sources under /external and make
away. You'll need to extract bionic(libc) and zlib(libz) from the
Android build as well, as ffmpeg libraries depend on them.
Create a dynamic library wrapping ffmpeg functionality using the
Android NDK. There's a lot of documentation out there on how to work with the
NDK. Basically you'll need to write some C/C++ code to export the
functionality you need out of ffmpeg into a library java can
interact with through JNI. The NDK allows you to easily link against
the static libraries you've generated in step 1, just add a line
similar to this to Android.mk: LOCAL_STATIC_LIBRARIES := libavcodec
libavformat libavutil libc libz
Use the ffmpeg-wrapping dynamic library from your java sources. There's enough documentation on JNI out there, you should be fine.
Regarding using ffmpeg for playback, there are many examples (the ffmpeg binary itself is a good example), here's a basic tutorial. The best documentation can be found in the headers.
The process is called transcoding. Pointers:
convert avi to 3gp using ffmpeg
FFMPEG on Android
Compile a port of ffmpeg to android. You'll get an ffmpeg executable file, put in your app. Setup you app to extract it in its data directory and mark it as executable. Then use it with ffmpeg command line options.
Build a wrapper JNI class, if you need to call it from java code only.