Home » Android » android – How to get continuously frame data from Camera2 API for streaming purpose?

android – How to get continuously frame data from Camera2 API for streaming purpose?

Posted by: admin May 14, 2020 Leave a comment

Questions:

We are working on real time video streaming using Lib streaming library. Lib streaming library supports old Camera api, all is working fine but we required to integrate Camera2 api to Lib streaming library. Some of functionality like video preview display using Camera2 api, we integrated but we need to get video frame data for stream continuously, how to get it? please suggest the way forward.

In Lib streaming library, they used below callback method for frame data:

mCamera.setPreviewCallback(new Camera.PreviewCallback() {
        @Override
        public void onPreviewFrame(byte[] data, Camera camera) {
            // here we get frame by frame data             
        }
    });
How to&Answers:

I didn’t completely get your question, but you can achieve this using setRepeatingRequest of camera2 API. It has a captureRequest parameter in which you can add an output surface where you want to get the frame data.