How to use prebuilt FFmpeg in Android Studio - android

I'm sure this is a very basic question but since this is the my first time messing around with the NDK, a lot of thing is still very unclear to me.
Use case:
I'm trying to develop a video scrubbing feature so fast and accurate frame seeking is crucial. I've tried most of the available players out there but the performance is still not up to my demand. That's why I'm going down the FFmpeg route.
Basically, what I'm looking for is FFmpeg input seeking. I've tried WrtingMinds' ffmpeg-android-java. However it is a file based implementation which means the out.jpg need to be written to external memory and read back which has a big hit on performance (roughly 1000 milliseconds for 1 seek).
That's why I'm trying to built my own FFmpeg player to do the input seeking in JNI and push back the byte[] to be displayed in Java.
Question: After a lot of struggling with the NDK, I've managed to set it up and successfully calling the JNI method from my Java code. The structure is as below:
MyApp
-app
-MyFFmpegPlayer
-build
-libs
-src
-main
-java
-com.example.myffmpegplayer
+HelloJNI.java
-jni
+MyFFmpegPlayer.c
After some fail attempt to build FFmpeg on Windows, I've decided to use WritingMinds prebuilt FFmpeg. However, after extraction they just come up as plain ffmpeg files (not .so file) so I don't really know how to use these.
It would be a great gratitude, if someone can just chime in and give me a good starting point for my next step.
Thank you so much for your time.

So to answer my own question which I should change to "How to build FFmpeg and use it with Android Studio", I have create a detail step-by-step instruction that's working for me (at May 24th 2016).
Sorry I can't post the whole instruction here as it is very long, plus it is easier for me to keep 1 source of information up-to-date.
I hope this can help someone as I know there is way too much confusing and contradicting information regarding this topic out there.

Related

Android: Build a decoder library from Jpeg to MP4 video

I am working on Android 2.2, and my goal is to covert a sequence of images to mp4 video, MPEG-4_Part_14, to be more exact.
The most reasonable solution would be using FFmpeg libraries, and compile them to Android using NDK. How ever I am looking for solution without NDK.
I do not expect from you to build this tool for me, or find some one else who did. I spent quit of time now searching for that, and it's some thing that probably no1 one did yet.
So the only thing that I am asking, is help me find the specs so I be able to build the decoder by my self. I know that it's not a trivial task(May be this is why no one did it yet), but I want to do it any way. So please just help me start it.

FFmpeg - Finally compiled. Now what?

OK So here is my story:
I am creating an app that requires me to take a couple images and a video and merge them together. At first I had no idea what to use, never heard of ffmpeg or ndk.. After around 5 days of battling NDK, switching to Ubuntu and going crazy with ndk-build commands I finally got FFmpeg to compile using the dolphin-player example. Now that I can run ffmpeg on my computer and android device I have no idea what to do next.
Here are the main questions I have:
To use FFmpeg, I saw that I need to use some sort of commands. First off what are these commands, where do I run them?
Second of all, Are the commands all I need? By that I mean can i just run my application normally, somewhere in it execute the commands in some way and it will do the rest for me? or do I need some sort of element in the code, for example VideoEncoder instance or something..
Third of all, I saw people using NDK to use FFmpeg, Do I have to? Or is it optional? I would like to avoid using C if possible as I don't know it at all..
OPTIONAL: Last but not least, Is this the best way of handling what I need to do in my application? If so, can someone guide me in a brief manner of how to use FFmpeg to accomplish said task (mention commands or anything like this)..
I know it's a wall of text but every question is important to me!
Thank you very much stackoverflow community!
I see my answer may no longer relevant to your question but I still put it here as I've recently gone through that very same path and I understand the pain as well as the confusion causing by this matter (setting up NDK using mixed gradle plugin take me 1 day, building FFmpeg takes 2 days and then fail at wtf am I supposed to do next??)
So in short, as #Daniel has pointed out, if you just want to use FFmpeg to run command such ask compressing, cutting, inserting keyframes... then Writing mind's prebuilt FFmpeg Android Java is the easiest way to get FFmpeg running on your app. The downside is since it just run command so it needs to take an input and an output file for the process. See my question here for further clarification.
If you need to do more complex task than this then you have no choice but building the FFmpeg as a library and calling API from it. I've written down step by step instruction that work for me (May 2016). You can see it here:
Building FFmpeg v3.0.2 with NDK r11c (please use Ubuntu if you don't want to rebuild the whole thing, Linux Mint fails me)
Using FFmpeg in Android Studio 2.1.1
Please don't ask me to copy the whole thing here as its a very long instruction and it's easier for me to keep 1 source of information up-to-date. I hope this can save someone's keyboard ;).
1, FFmpeg can be either an app or a set of libraries. If you use it as an app (with an executable binary installed), you can type the commands in a terminal. The app only has limited functions and may not solve your problem. In this case you need to use ffmpeg as libraries and call APIs in your program.
2, To my understanding the commands cannot solve your problem. You need to call ffmpeg APIs. There are a bunch of sample codes for video/image encoding/decoding. You probably also need a container to package the outcome, and ffmpeg libraries can also do that.
3, NDK is preferred by me, since ffmpeg are written in C/C++. There are JAVA wrappers for ffmpeg; if you use them, NDK is not required. However, not all functions in ffmpeg are wrapped well - you may try. If not, then go back to the NDK solution.
4, The simplest way is to decode all your video/images into raw frames, combine them with desired order, and encode them. However in practice this consumes too much memory. The key point then becomes: how can I do the same on the fly? It's not too hard once you reach this step.

Simple Build of Libavcodec.so and libavformat.so on Mac

Who needs ffmpeg? Not me. What I need is to be able to decode a video stream along with its audio stream, so that can put the frames on an opengl surface in sync with the audio.
FFmpeg is a tool that transcodes video. That is not what I need. I need its libraries.
The problem is that every example for building FFmpeg includes junk I just dont need. The latest example I wasted my time on:
https://github.com/appunite/AndroidFFmpeg
uses things like freetype2 that I really, REALLY, do not need. Whats more annoying is that it wont even build as described because the example references freetype, not freetype2 so the build steps are broken. Don't even get me started on the problems I had with libtool.
The kicker is finding libav.org, where they describe on their about page the chaos in the ffmpeg project. Perhaps that is why this is so difficult.
So, should it be so hard to build just the shared libs? Can someone point me to some documentation, or a tutorial that works? I admit that this is new territory for me but all I have found using Google is chaos.

Looking for method to combine images to make a video through phonegap platform for android and ios

I'm looking to write an application that could combine images and then to form a video. I'm working with Phonegap framework to be available for use on Android and IOS.
My question is what sort of process is involved to achieve this?
At this stage I've tried to read about ffmpeg, most of the questions existing on stackoverflow talk of having to get the source, compiling to make a series of libraries for use. With those libraries it needs to be tied in with the Android/IOS libraries? (I notice there is an 'android.jar' with the project file in eclipse. Would it exist in there?) Afterwards my confusion lies with how is this implemented into Phonegap. Develop a plugin?
Just to add, libav according to wiki, has hardware accelerated H.264 decoding whilst using x.264 for encoding for Android. How does that work? Is this something accessed from libav libraries and then have to compiled in within the android.jar?
I may have confused terms in trying to describe what I do not know.
Any help would be appreciated.

Aubio for BPM tracking on Android

I am working on a android audio project which requires BPM tracking. I decided that writing my own would not be a good idea and after looking around, I found a few libraries that does BPM tracking such as aubio, vamp, echonest etc. Out of the lot aubio seemed a good choice. The problem is I cannot find good documentation that can help understand how I can use the library, such as, what sort of input audio formats are compatible (should i pre-process the audio before passing it to the function), etc.
Can you point me to some documentations or implementations of aubio to some open source projects (on android would be a bonus).
If you think there is an easier way (another algorithm/library) to port on android (preferably in c), let me know.
Thanks.
I used the make files provided with aubio to cross compile it for android. I followed some tutorials such as this which shows how to cross compile open source libraries. As for the documentation for aubio, i just used it several times to understand how it works (i studied how the examples worked) and read the phd thesis of the author to get a rough idea on the technical stuff.

Categories

Resources