I\'m using Android 2.2 with Eclipse.
I would like to make an application that captures video, and for each frame, its send it as a bitmap to a method that processes
If you want to do more complicated real-time video processing, I would highly recommend OpenCV for Android.
OpenCV is a computer vision library that enables you to process video in real-time, and it has libraries to perform simple tasks like detecting edges or more complicated tasks like detecting faces and matching features.
You can get OpenCV working in your Android cellphone in one day, especially because it includes extensive documentation and examples.
You can potentially use Camera.setPreviewCallback
with Camera.PreviewCallback#onPreviewFrame
to listen for preview frames coming from the camera.
Code for 2d Barcode scanners might be a useful starting point: ZXing
It is simple enough to accomplish the following steps using the Android SDK:
Camera.PreviewCallback
will return a byte[]
of data representing the frame in a number of possible image formats.Bitmap
object to make working with the pixels easier. In 2.2, you have the option of using the NDK and jnigraphics to work with a Bitmap's pixels in native code, which is significantly faster than at the Java layer.Bitmap
and display it. For fast moving data, you would want to display this on a SurfaceView
; using the lockCanvas()
and unlockCanvasAndPost()
methods available from the SurfaceHolder
that view contains.If this is all you are wanting to do, you could accomplish this with little difficulty. However, this is not the same as capturing video. Android does not currently provide hooks for you to stream frames out into an encoded video container (MPEG4, 3GP, etc.) in real-time. It's video capture capabilities are wrapped up tightly into the MediaRecorder
which controls the process from frame capture all the way to writing the encoded video. You would need a 3rd part library such as FFMPEG (which has been built and run using the NDK layer a number of times in Android applications) to assist in the encoding process of your modified frames.
I know you have a 2.2 target, but Android 4.0 does provide some relief here as they have released a new version of the NDK which allows one to have more say in what happens when reading image data from a stream before handing it to the presentation layer. However, I have not spent enough time with it to know whether it could be recommended for your situation.