Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why FPS is not same as original camera app

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?

like image 468
Cheok Yan Cheng Avatar asked Dec 30 '11 04:12

Cheok Yan Cheng


2 Answers

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.

like image 94
John O'Connor Avatar answered Sep 30 '22 13:09

John O'Connor


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 );
like image 38
ggurov Avatar answered Sep 30 '22 13:09

ggurov