Webcam Tester App is a free app that checks if iCubie USB camera can work with your Android device as an external camera.
Download this app from Google Play Store or this web site.
Designed exclusively for iCubie USB camera, iCubie Camera App is a free camera app to preview and record video.
It also provides the camera service running in background to allow third party applications to seamlessly obtain the video service from iCubie USB camera.
Absolutely NO rooting of your Android device is required for installation and use.
Download this app from Google Play Store or this web site.
A free app that demonstrates how iCubie Camera Service can be easily integrated into third party Android apps.
Its sources codes are available for downloading.
Download this app from Google Play Store or this web site.
iCubie Camera is an app that provides not only the GUI features for taking photos and recording video from the iCubie camera but also the iCubie Camera Service that urns in the background.
The iCubie Camera Service running in the background does all the heavy lifting:
Yet the iCubie Camera Services provides a very simple and easy-to-use set of APIs to allow quick and smooth integration of iCubie camera features into 3rd party Android applications.
You can download the sources codes of SimpleCamera app that demonstrates the integration.
Follow the steps below to integrate iCubie camera features into your Android platform.
Define a video window in Activity layout. See activity_simple_camera.xml for example.
Add the following lines into your Activity layout XML file.
<com.picoinstruments.android.simplecamera.SimpleCameraPreview android:id="@+id/cp" android:layout_width="fill_parent" android:layout_height="fill_parent" android:focusable="true" android:linksClickable="true" />
It defines a window for video preview. SimpleCameraPreview class (defined in SimpleCameraPreview.java) automatically renders live video onto it.
Make sure you update the package name accordingly.
Change
com.picoinstruments.android.simplecamera.SimpleCameraPreviewto
com.your_company_name.android.simplecamera.SimpleCameraPreview
Copy both sample files SimpleCameraPreview.java and CameraService.java into your /src folder. Again, make sure you update the package name accordingly.
SimpleCameraPreview class registers itself with the iCubie Camera Service, receives video frames from the Service and displays the video frames as RG565 Bitmaps. CameraService class provides a set of iCubie Camera Service APIs (more details below).
In your Activity class, set the activity content to the video window view.
public class SimpleCameraActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* Hide the window title, set full screen with Landscape orientation. */ requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_simple_camera); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }
That is all it takes. Once the iCubie camera is plugged into your Android device, you will get a live video. (iCubie Camera app must have been installed.)
Command | Description |
---|---|
REQ_REGISTER_CLIENT | Register with the Service. |
REQ_UNREGISTER_CLIENT | Application must de-register with the Service in order to free the resources allocated to it during registration. |
REQ_GET_FRAME | Instruct the Service to start (or stop) sending captured video frames to the application. |
REQ_TAKE_PHOTO | Instruct the Service to take a snapshot and save it as a JPEG image file. |
REQ_RECORD_VIDEO | Instruct the Service to start (or stop) video recording and save the video recording as a MP4 video clip. |
Let us know any problems you may encounter during the integration. We can help. Leave us a message or feedback at the bottom of this page.
In the iCubie Camera app, we used FFmpeg to encode video in MPEG-4 part-12 format only for Android devices of of API 18 (4.3 Jelly Bean) or older. FFmpeg is linked in the app as four shared NDK libraries (ibavcodec-55.so, libavformat-55.so, libavutil-52.so and libswresample-0.so).
We mainly followed the instructions by roman10 to compile FFmpeg source code package for Android platform. Below are steps we actually took.
It is assumed that you have already had Android NDK toolchain installed and have the knowledge building NDK library for Android applications. In the following paragraphs, NDK_INSTALLATION refers to your NDK installation. In our case, it is $HOME/android-ndk-r9d on Mac OS X machine.
Download the latest FFmpeg source code package from the official FFmpeg web site.
At the time of this writing, the FFmpeg version is 2.2.3.
cd NDK_INSTALLATION/sources git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
Edit the file NDK_INSTALLATION/sources/ffmpeg/configure.
Replace the following linesLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)' LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"' SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)' SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'with
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)' LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"' SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)' SLIB_INSTALL_LINKS='$(SLIBNAME)'
Decide which FFmpeg components you will need. In our case, all we needed were mpeg4 video encoder and mp4 muxer so we disabled everything else. Doing so can significantly reduce the footprint of the FFmpeg libraries. In our case the sizes are:
-rwxr-xr-x 1 pico pico 515548 Jun 11 11:50 libavcodec-55.so -rwxr-xr-x 1 pico pico 214912 Jun 11 11:50 libavformat-55.so -rwxr-xr-x 1 pico pico 177704 Jun 11 11:50 libavutil-52.so -rwxr-xr-x 1 pico pico 79260 Jun 11 11:50 libswresample-0.so
Create the file NDK_INSTALLATION/sources/ffmpeg/build_android.sh with the following lines as the build shell script. Enable whatever components you will need.
#!/bin/bash NDK=$HOME/android-ndk-r9d SYSROOT=$NDK/platforms/android-12/arch-arm/ TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64 function build_one { ./configure \ --prefix=$PREFIX \ --enable-small \ --enable-shared \ --disable-static \ --disable-encoders \ --disable-decoders \ --disable-muxers \ --disable-demuxers \ --disable-parsers \ --disable-bsfs \ --disable-protocols \ --disable-filters \ --enable-encoder=mpeg4 \ --enable-muxer=mp4 \ --enable-protocol=file \ --disable-doc \ --disable-ffmpeg \ --disable-ffplay \ --disable-ffprobe \ --disable-ffserver \ --disable-avdevice \ --disable-doc \ --disable-symver \ --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \ --target-os=linux \ --arch=arm \ --enable-cross-compile \ --sysroot=$SYSROOT \ --extra-cflags="-Os -fpic $ADDI_CFLAGS" \ --extra-ldflags="$ADDI_LDFLAGS" \ $ADDITIONAL_CONFIGURE_FLAG make clean make make install } CPU=armv7-a PREFIX=$(pwd)/android/$CPU ADDI_CFLAGS="-marm -march=$CPU -mfpu=neon" build_one
We only targeted the armv7-a CPU architecture as it is widely supported by most Android devices out there. Tailor your own.
Make sure you set up environment variables $NDK, $SYSROOT and $TOOLCHAIN accordingly.
Also make sure your build shell script can be executed.
chmod +x NDK_INSTALLATION/sources/ffmpeg/build_android.sh
Build FFmpeg
cd NDK_INSTALLATION/sources/ffmpeg/ ./build_android.sh
It may take a while, really. Once done, the compiled libraries and needed include files are placed in the folder NDK_INSTALLATION/sources/ffmpeg/android.
Make all the compiled FFmpeg libraries available to your NDK project.
Create the file NDK_INSTALLATION/sources/ffmpeg/android/Android.mk with the following lines.
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE:= libavcodec LOCAL_SRC_FILES:= lib/libavcodec-55.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libavformat LOCAL_SRC_FILES:= lib/libavformat-55.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libswscale LOCAL_SRC_FILES:= lib/libswscale-2.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libavutil LOCAL_SRC_FILES:= lib/libavutil-52.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libavfilter LOCAL_SRC_FILES:= lib/libavfilter-4.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libswresample LOCAL_SRC_FILES:= lib/libswresample-0.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY)
Import FFmpeg libraries into your NDK build project.
Append the following lines to your Android project's NDK makefile jni/Android.mk.
$(call import-module,ffmpeg/android/armv7-a)
Here is an example how we built our videoencoder NDK library using the imported FFmpeg library modules.
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := videoencoder LOCAL_SRC_FILES := videoencoder.c LOCAL_LDLIBS := -llog LOCAL_SHARED_LIBRARIES := libavformat libavcodec libavutil libswresample include $(BUILD_SHARED_LIBRARY) $(call import-module,ffmpeg/android/armv7-a)
Load the NDK libraries in your Java class that calls native NDK functions.
Here is an example of our VideoEncoderFFmpeg class.
public class VideoEncoderFFmpeg { ... /* load up shared libraries */ static { System.loadLibrary("avutil-52"); System.loadLibrary("avcodec-55"); System.loadLibrary("avformat-55"); System.loadLibrary("swresample-0"); System.loadLibrary("videoencoder"); } }
That is all it takes. Have fun building FFmpeg and NDK. Let us know if you need help from us. You can leave us a message at the bottom of this page.