3
votes

I want to open device camera for 3 functions:

  • motion detection

  • video record

  • stream video with rtsp

I can do 2 first functions by initialize device camera preview and work with the return byte[] data of camera object.

mPreviewCallBack = new android.hardware.Camera.PreviewCallback() {
 @Override 
 public void onPreviewFrame(byte[] data, android.hardware.Camera camera) {
                       // motion detection 
                       detectMotion(data);
                       // auto record video if motion detection
                       recordVideo(data);
                       // stream preview to client device
                       ??? 
}

but i can not do the 3rd function yet. I did try some OS (libstreaming, rtmp-rtsp-stream-client-java ,..) but they both will open new camera preview again to do stream.

Do you have any comment about how to only stream rtsp camera byte[] data of existing camera preview?

1
Update: i could stream the camera preview to client using Live-555 (github.com/papan01/Live555-server-android). Btw, it need to create a customized surface first then encode the surface to stream to Client application. - Tran Intent

1 Answers

1
votes

If you look inside the rtmp-… library, you can find onPreviewFrame() implementation. You can extend this method by adding your detection. If I understand correctly, this library can handle video recording for you.

If you (rightfully) prefer to use a more established library, your choice should be WebRTC. But hooking your face detection into WebRTC may be harder, and may involve C++.

On the other hand, if your task is very limited , and the two devices share the same wireless LAN with minimal interference, you don't need advanced transport protocol as RTSP. Direct TCP socket (for encoded frames) could be enough, and this can be added quite painlessly.