6

I tested with original camera application (video mode) comes with Samsung Galaxy Tab 8.9. The saved front camera video able to achieve 24 fps, 640x480. (By looking at the properties of video file after transfer to Windows machine)

However, while I write front Camera code to test.

mCamera2.setPreviewCallbackWithBuffer(new PreviewCallback() {
    public void onPreviewFrame(byte[] data, Camera camera) {
        // image processing code placed here.
    }
});

The maximum result I can achieve is (without saving video to disk. I merely measure the callback function onPreviewFrame triggered rate)

  • 15 fps
  • 320x240, 800x600

I would like to have performance same as Samsung original camera app. May I know am I missing certain technique?

Lelouch Lamperouge
  • 8,171
  • 8
  • 49
  • 60
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
  • Is that doing raw frame capture? even 800x600 @ 24bit @ 15fps = 21meg/sec of data. Anything above that would probably exceed the write speed of the internal flash storage. – Marc B Dec 30 '11 at 04:07
  • @MarcB please looked at my revised question with more detail. – Cheok Yan Cheng Dec 30 '11 at 06:11

3 Answers3

5

The reason you're seeing these results is that your callback is getting a sampling of the video rather than the actual video.

When the camera is dumping it's output to the file system, it's doing a very low level write operation that copies the data from the camera's video buffer to the file system, without ever touching the JVM. This is required to keep the video at a high quality and low latency, and ensures a smooth final video. If you need to do video processing on the actual video, it is better done after the video is already done being recorded.

The preview callback is merely giving you a sample of the actual video capture, not the entire video capture -- since most 15fps videos will still look smooth, the preview callback is only giving you a lower resolution, lower fps preview version of the actual video being captured. Even the built-in samsung capture application will only show the preview version, because that's all the preview interface is being given.

It would be impossible to get an accurate benchmark of video recording in Android from anything other than the file system dump or the low-level byte array data structures (using a JNI wrapper for example). It would be easy enough, but attempting to do it directly would block input reading from the camera and blow your benchmarks anyway.

John O'Connor
  • 5,244
  • 2
  • 24
  • 29
  • 1
    Interesting enough. Do you have any information how I can access camera video buffer directly? As far as from the information I obtain from android-ndk group : http://groups.google.com/group/android-ndk/browse_thread/thread/ec7e28a83fa93c8c, it seems that accessing camera directly from NDK is not officially being supported. – Cheok Yan Cheng Dec 31 '11 at 15:22
  • That's my understanding as well - you can't access the raw bytestream from the camera itself except through the file after the fact since there are no NDK / SDK accessors. It might be worth digging into the Android source code to see if there are any hooks that could possibly be available: android/frameworks/base/media/java/android/media/MediaRecorder.java – John O'Connor Jan 11 '12 at 23:35
  • Oh well, I guess nothing much I can do on my side. – Cheok Yan Cheng Jan 17 '12 at 16:50
  • So, you mean if I count the fps of the preview in `onPreviewFrame()`, I'm not getting the actual frame rate that I'm seeing on the screen? If that's so, is there any way of calculating the frame rate of the actual preview? – timemanx Oct 02 '13 at 23:44
  • Okay, I understand now. You mean the preview itself is of 15fps. – timemanx Oct 03 '13 at 06:48
4

Camera FPS depends of lighting conditions and AutoExposure parameter. For getting fixed frame rate in all lighting conditions (from API 14, Android 4.0):

Camera.Parameters p = camera.getParameters();
p.setPreviewFpsRange( 30000, 30000 ); // for 30 fps
if ( p.isAutoExposureLockSupported() )
     p.setAutoExposureLock( true );
camera.setParameters( p );
ggurov
  • 1,496
  • 2
  • 15
  • 21
0

Maybe a MediaRecorder API could be better in combination with Camera API instead of capturing images using PreviewCallback...

http://developer.android.com/guide/topics/media/camera.html#capture-video

http://developer.android.com/reference/android/media/MediaRecorder.html

Pavel Sedek
  • 519
  • 5
  • 13