Friday, September 18, 2015

Gstreamer Camera Source for Android

Note: This article is outdated. The source element for android camera has been merged already. 

Using Android Camera via Gstreamer is not easy. There are two unofficial implementations; one is OpenWebRTC, another is android hardware camera source which is what I’d like to introduce here.

Actually, a source element for Android Hardware Camera has been developed already in Gstreamer 0.10. However, due to license problem and the other issues which I don’t know, the latest implementation was opened recently. Almost of Gstreamer developers might want to port this work from 0.10 to 1.0, but it’s not easy to fill the time gap between them. Perhaps, it’s not about level of difficulty, but rather it is about time consuming.

To use Android Camera with Gstreamer 1.0, we need to get few patches from my personal repository because review on my proposed patches are in progress.

No one recommend building gst-plugins-bad for Android platform as it is. It requires a bit annoying tasks like setting environment variables, copying files into specific directories and typing hundreds of commands. Simply, we can use cerbero to get Gstreamer SDK image, but it’s not the scope of this article. :)

Here’s an url for pre-built SDK to make all thing simple.

This image should be extracted in a proper directory, in here, ~/Android/gstreamer I used.

$ mkdir ~/Android/gstreamer
$ cd ~/Android/gstreamer
$ tar jxvf /somewhere/gstreamer-1.0-android-armv7-1.5.90.tar.bz2


$ export GSTREAMER_ROOT_ANDROID=~/Android/gstreamer

Before compiling gst-camera-app, we need to set PATH variable with Android SDK as well as NDK. For SDK, tools and platform-tools directories should be in PATH. Regarding to NDK, the path as itself is sufficient to use ‘ndk-build’ command.

Now, we can clone gst-camera-app.

In the directory of test application, Android project properties should be updated.

$ android update project -p .

Then, this application is ready to compile by just a command, ndk-build.

$ ndk-build 

However, if you want to get debug image, use this command instead.

$ ndk-build NDK_DEBUG=1

The test application uses glimagesink element. It causes a problem with android emulator so we need a real android device to test this application. Regarding to this issue, please refer to

The command, ndk-build, generates all of c objects to connect gstreamer with Java. Now, we can build Java classes and install Android package into a real device.

$ ant debug && ant installd


$ ant release && ant installr

Now, enjoy the camera.

No comments:

Post a Comment