I am trying to use FFMPEG library for Video compression on Android.
I've compiled the library using : http://bambuser.com/opensource and https://www.quora.com/What-are-the-steps-for-integrating-FFMPEG-on-Android
Now next step is NDK build of this. But I am not sure what all will go as LOCAL_SRC_FILES, LOCAL_LDLIBS and LOCAL_C_INCLUDES.
Apart from that what function should be called for compression in this library.
Please suggest.
For ffmpeg use on Android (or other platforms) there are a number of common approachs you can take:
invoke the command line from your program via EXEC command (has some limitations and drawbacks)
use a wrapper around the ffmpeg command line C program
Directly use the ffmpeg libraries, or more accurately the libraries that ffmpeg uses
The wrapper approach may be the easiest is you simply want to get the functionality working quickly.
There are several fairly well used wrappers available on GitHub - the ones below are particularly well featured and documented (note, I have not used these as they were not so mature when I was looking at this previously, but if I was doing something like this again now I would definitely build on one of these):
http://writingminds.github.io/ffmpeg-android-java/
https://github.com/guardianproject/android-ffmpeg
Using one of the well supported and used libraries will take care of some common issues that you might otherwise encounter - having to load different binaries for different processor types, and some tricky issues with native library reloading to avoid crashes on subsequent invocations of the wrapper.
Because this approach uses the standard ffmpeg cmd line syntax for commands it also means you should be able to search and find help easily on multiple different operations (as anyone using ffmpeg in 'normal' model will use the same syntax for the ffmpeg command itself).
Related
I am trying to run a neural network on Android in C++. The examples (https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/android) show how to use tensorflow using JAVA apis which call C++ using JNI functions. Has anyone tried to use tensorflow directly in C++ on Android? How can the tensorflow library be built and linked for using C++ apis on Android. Can you please guide me on that? I want to use C++ apis on Android in the similar way as done in iOS examples.
Here is how I solved this problem. Although there is not much documentation of using c++ apis on android and compiling and linking tensorflow to NDK, the makefile have important comments as well as there are associated scripts. Compilation steps are very similar to that of ios.
Install following dependencies a)autoconf b) automake c)automake. Then run tensorflow/contrib/makefile/download_dependencies.sh; I ran on May 10, 2017 repository for the first time, when it worked perfectly. In the later version around June 1, due to some changes in tensorflow/workspace.bzl, that I do not understand in download_dependencies.sh fails to recognise the tar files download_dependencies is trying to download. I just replaced workspace.bzl from May 10 repo commit.
Step 2 is to run tensorflow/contrib/makefile/compile_android_protobuf.sh like this
NDK_ROOT=absolute/path/to/ndk/folder ./tensorflow/contrib/makefile/compile_android_protobuf.sh
Run make. But first you may need to make some changes in Makefile. Replace -fPIE flags with -fPIC flags. Also add -fPIC flag to HOST_CXXFLAGS. Then run make like this:
make -f tensorflow/contrib/makefile/Makefile TARGET=ANDROID NDK_ROOT=absolute/path/to/ndk/folder
Alternatively one can also run build_all_android.sh which runs all 3 steps in one go, but you may need to do Makefile changes for flags.
This generated tensorflow/contrib/makefile/gen/protobuf/lib/libprotobuf.a and tensorflow/contrib/makefile/gen/lib/libtensorflow-core.a; This can be linked to Android NDK project in Android.mk file under LOCAL_LDLIBS. One should use these Linked flags -Wl,--build-id -Wl,--allow-multiple-definition -Wl,--whole-archive Also -std=c++11 in LOCAL_CFLAGS in Android.mk file and APP_STL := gnustl_shared in Application.mk file.
This should be sufficient to build a shared library of your NDK project.
100% possible, with a small caveat...
Most of Android's UI is done in Java. You can create a native activity, but to get any output to the screen, you need to either use OpenGL (which doesn't have all the nice Android UI Views) or you will need to transition the JNI barrier to get your data output to and from the native code to display to the user.
Depending on your familiarity with OpenGLES, EGL, etc.. You might opt to transition the JNI barrier instead of creating a native_activity, but at a much smaller cross section.
You could create a Runnable and signal it when there's work to be performed. Use a concurrent queue (in Java) to submit work and another (concurrent) queue to receive results from. The Runnable pops the work queue, calls a single JNI/C function to submit the work and return a JSON string. Then it submits the work to the finished queue.
I'm trying to use FFmpeg in a new app and found these two repositories on GitHub: http://hiteshsondhi88.github.io/ffmpeg-android/ and http://hiteshsondhi88.github.io/ffmpeg-android-java/.
What are their differences? I mean, Android NDK is just a way to put native code together with your Java code, right? If so, using FFmpeg-android as a shared native library and using FFmpeg-android-java which seems to be a java library that encapsulates calls to the shared native library, are the same thing. Or am I wrong?
Thank you
The second one includes a full android project and precompiled libraries. The first one is only a bunch of shell scripts that will download and compile different tools (including ffmpeg) using the NDK that you provide.
I want to use some function calls(commands) designed for linux. I can use them by enter the key words in adb(Android CML).
Here I found some works some people did.
wget (because it isn't included in most Android device )
Iperf
But after reading their methods or suggestions, I can only understand that I need to use Android NDK and write the correct makefile. I have no idea about building others source code (most of them are C/C++) for linux(only need to use 'make' command mentioned in their README file). The official NDK document is for Java environment to call C lib mainly.
Are there some HOWTO, courses or suggestions for this. Thanks!
I have compiled single cpp file program. I try to compile a alternative version iperf
https://github.com/tierney/iperf
It seems to be relative to lib ,some header files, and multiple c files. I failed to compile by enter all c files normally. Is there anything I missed?
yeah you need the NDK, it offers an C/C++ compiler for Android.
In general the steps are all the same:
Setting up the NDK (I wrote a small how-to, but it's for Arch-Linux and the fish-shell, Windows how-to)
Adjusting your make file (instead of gcc compiler use Android NDK compiler, and so on)
Remember that Android uses Bionic C library, so only use functions supported by it
Run make, push the program to your device and make it executable
Of course, this is just an overview how it is done. You should try it and then ask specific questions if you run into troubles.
NDK is mostly intended to extend the Java apps, but you can download NDK and create a standalone toolchain from it (see http://www.kandroid.org/ndk/docs/STANDALONE-TOOLCHAIN.html). Now you have a cross-compilation environment which is very similar to standard Linux dev environment.
In addition, for small executables and for testing only, you can also cross-compile and link statically to the libc. This way you don't have to worry about Bionic which could be a loss of time.
I want to write an Android application that is able to display list of exported functions by a shared library (.so).
nm/objdump/readelf tool is only available for Windows/Linux. So I have thought about compiling platfor_external_elfutils to get a toolchain with nm or objdump tool.
However, this is not a good solution considering the big dependencies the toolchain may cause (can be up to xx MB).
I want to ask if there is any available simple code to achieve the purpose without having to compile and attache the whole toolchain in my app.
This is probably too late for the original poster, but libelf can be built as a static library (libelf.a) from Android sources, at least since JB4.2. Just use
make libelf
In the main directory to build it.
If someone knows how to build it as a dynamic library/shared object that would be much appreciated.
You can use libelf library (from elftoolchain - it's BSD licensed) to parse the binary. libelf comes with source for elfdump utility that dumps various information about ELF file including export list. Just strip out the source you don't need and you're ready. Executable for this won't take more than 100KB.
Currently I'm using ffmpeg to develop a media player on Android. I've compiled ffmpeg using ndk. And next I have to use the built module to code. So here comes the question: how to use the compiled ffmpeg?
Firstly I thought since I have to import the ffmpeg module, I have to read $(ndk)/docs/IMPORT-MODULE.html. But when it came to practice, things didn't work out.
After a time of struggling, I found there's docs called PREBUILTS.html, which was exactly what I want. So I built a new project, copy libffmpeg.so to $(newProject)/jni and write Android.mk step by step as the docs depicted. It hasn't worked fine yet, but I believe I've found the right way.
So here comes the question: What's the difference between IMPORT-MODULE and PREBUILTS? Does IMPORT-MODULE means that the imported module could work itself (could be distributed as binary), and PREBUILTS means it's only a dynamic library?