Ahmad Arslan
Ahmad Arslan

Reputation: 4528

Skipping the Frame on onPreviewFrame(byte[] data, Camera camera)

I want to save the frame in the Arraylist code works but the problem is frames are skipping while capturing the video. CameraArrray is the arraylist and ModelFrameProcess is the model class which takes bytes array and save into the arraylist. I have fixed the framerate as 15.

@Override
        public void onPreviewFrame(byte[] data, Camera camera) {

                 CameraArray.add(new ModelFrameProcess(data));
}

Sometimes frame rates are dropping up to 6 and sometimes it will take more than 20 frames. Any help ??

Upvotes: 0

Views: 1026

Answers (1)

Alex Cohn
Alex Cohn

Reputation: 57173

To achieve best frame rate, you should avoid garbage collection. No allocations (new) should be made during acquisition.

You can use Camera.setPreviewCallbackWithBuffer(), but this bequires copy of the frame data aside, you should not add to the ArrayList the data bytearray received in the callback.

Often, the callbacks happen on the main (UI) thread. This may account to unstable frame rate. To push the callbacks off the UI thread you should use an eventLoop.

Upvotes: 1

Related Questions