Ricky Casavecchia
Ricky Casavecchia

Reputation: 650

Stream live video from camera on android

I am attempting to make an app that will stream a video from the camera of an android phone over the internet using the TCP or UDP protocol. I am currently able to transfer a byte array from the android phone to my computer which is running a server that I have written in C#. I have done streaming video before by sending .jpeg's over the network and showing them at 30 fps but this uses up too much bandwidth.

First what would be the best way of capturing the images from the camera? I'm looking at...

onPictureTaken(byte[] data, Camera camera)

or

onPreviewFrame (byte[] data, Camera camera)

I'm just interested in the byte[] data, taking that and encoding / compressing it then sending it over the network.

Second, how should I turn these frames into a compressed video that is a byte array that can be streamed over the network? I don't care too much about video quality, I care more about cutting down on bandwidth.

Here is what I am trying to do, but I don't need high quality video. https://code.google.com/p/spydroid-ipcamera/

Upvotes: 5

Views: 13513

Answers (2)

Marko
Marko

Reputation: 151

If you're concerned about bandwidth, maybe you should try to send a JPEG image byte array? Since data byte array is in YUV format, it's bigger than JPEG one. When running a JPEG compression, you're able to define it's quality, which would impact on sending byte array size.

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

 YuvImage image = new YuvImage(data, ImageFormat.NV21,
                            size.width, size.height, null);
 baos = new ByteArrayOutputStream();
 int jpeg_quality = 100;

 image.compressToJpeg(new Rect(0, 0, size.width, size.height),
                         jpeg_quality, baos);

 byte[] sending_array = baos.toByteArray();

} 

where size was previously defined as

Camera.Size size = parameters.getPreviewSize();

Upvotes: 0

stinepike
stinepike

Reputation: 54722

if you are planning to encode data by yourself by using any encoder then user

onPreviewFrame (byte[] data, Camera camera)

Or you can try in a different method by sending rtsp stream. SpyDroid is a very nice project to look at to learn about this method.

Upvotes: 4

Related Questions