17

I am working on application that does some real time image processing on camera frames. For that, I use preview callback's method onPreviewFrame.
This works fine for cameras that support preview frames that have resolution at least 640x480 or larger. But when camera does not support such large camera preview resolution, application is programmed to refuse processing such frames. Now, the problem I have is with phones like Sony Xperia Go. It is a very nice device that can record video up to resolution 1280x720, but unfortunately maximum camera preview size is 480x320, which is too small for my needs.

What I would like to know is how to obtain these larger camera frames (up to 1280x720 or more)? Obviously it has to be possible because camera application has the ability to record videos in that resolution - therefore this application somehow must be able to access those larger frames. How to do the same from my application?

Application has to support Android 2.1 and later, but I would be very happy even if I find the solution for my problem only for Android 4.0 or newer.

This question is similar to http://stackoverflow.com/questions/8839109/processing-android-video-frame-by-frame-while-recording, but I don't need to save the video - I only need those high resolution video frames...

Zoe
  • 27,060
  • 21
  • 118
  • 148
DoDo
  • 2,248
  • 2
  • 22
  • 34
  • If you can jump to SDK 11+ there's ``SurfaceTexture`` available you can use for camera preview. And if OpenGL is enough for your image processing needs you could give it a shot in order to see whether SurfaceTexture based preview had higher resolution. – harism Jan 16 '13 at 17:29
  • Good point. I thought that Camera.Parameters.getSupportedPreviewSizes() depends only on camera, but not on the surface to which camera is previewing. I'll try that. On the other hand, is it possible to access camera via V4L2 (VideoForLinux2) interface? Maybe with V4L I'll have better control of the camera... – DoDo Jan 17 '13 at 09:09
  • First of all, take in account that onPreviewFrame gives you a YUV (NV21) image, unless you specify another preview format in your camera object. Because of the lack of the methods in the android sdk for working with this kind of format, it would be a pain in the ass. This format it's the default one, so if you want 100% compatibility with all devices you'll have to manage this. Of course you can convert the image to a more manageable format, but this is costly in terms of performance, so as you're telling, if you want realtime processing this would be a problem for you – Mario May 28 '13 at 20:26
  • Mario, I am aware of the image format that is given in method onPreviewFrame and I already have methods to handle this format. The problem is only that on some devices (e.g. Sony Xperia Go), the maximum size of the preview frame is 480x320, but device is able to record HD video (1280x720). This means that device's camera sensor has the ability to produce high resolution video frames. I just want to access them. If I use MediaRecorder, then I can record HD video, but I would like to have HD frames in onPreviewFrame. – DoDo May 29 '13 at 06:49

4 Answers4

6

It seems the only thing you can do is decoding frames from MediaRecoder data. You may use ffmpeg to decode recoreder data from LocalSocket.

Hope the following open source projects may help:

ipcamera-for-android: https://code.google.com/p/ipcamera-for-android/

spydroid-ipcamera: https://code.google.com/p/spydroid-ipcamera/

aarontang
  • 229
  • 3
  • 7
  • Thanks for sharing those projects and idea. Looks like that is what I've been looking for. – DoDo Feb 27 '14 at 11:22
0

You should probably take a look at the OpenCV library. It has methods that allow you to receive full frames.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
0

I have an impression: video preview size is small, and is slow, slower than the set video recording frame rate.

I was once trying to look for solutions on this. It seems a better way is to get the video stream from the video recorder, then directly process the data from the video stream.

You could find some examples on Android ip-camera.

user1914692
  • 3,033
  • 5
  • 36
  • 61
0

You can use this library:

https://github.com/natario1/CameraView

This library has addFrameProcessor listener that in process function has Frame parameter.

If you need to record video while frame processing, you need to use from takeVideoSnapshot function of CameraView. takeVideo stop frame processing until complete video recording in latest version I tested 2.6.4.

halfer
  • 19,824
  • 17
  • 99
  • 186
Sayed Abolfazl Fatemi
  • 3,678
  • 3
  • 36
  • 48