Streaming Video from Android Camera to Server

Transfer real-time video stream to server using Android

I can see you have designed the three stages correctly, in your second diagram.

So what you need is to determine how to choose among these protocols and how to interface them.
No one can give you a complete solution but having completed an enterprise project on Android Video Streaming I will try to straighten your sight towards your goal.

Sample Image

There are three parts in your picture, I'll elaborate from left to right:

1. Android Streamer Device

Based on my experience, I can say Android does well sending Camera streams over RTP, due to native support, while converting your video to FLV gives you headache. (In many cases, e.g. if later you want to deliver the stream on to the Android devices.)

So I would suggest building up on something like spyDroid.

2. Streaming Server

There are tools like Wowza Server which can get a source stream
and put it on the output of the server for other clients. I guess
VLC can do this too, via File-->Stream menu, an then putting the
RTSP video stream address from your spyDroid based app. But I have
not tried it personally.

Also it is not a hard work to implement your own streamer server.

I'll give you an example:

For Implementation of an HLS server, you just need three things:

  1. Video files, segmented into 10 second MPEG2 chunks. (i.e. .ts files)
  2. An m3U8 playlist of the chunks.
  3. A Web Server with a simple WebService that deliver the playlist to the Clients (PC, Android, iPhone, mostly every device) over HTTP. The clients will then look up the playlist file and ask for the appropriate chunks on their according timing. Because nearly all players have built-in HLS support.

3. The Client-Side

Based on our comments, I suggest you might want to dig deeper into Android Video Streaming.

To complete a project this big, you need much more research. For example you should be able to distinguish RTP from RTSP and understand how they are related to each other.

Read my answer here to get a sense of state-of-the-art Video Streaming and please feel free to ask for more.

Hope you got the big picture of the journey ahead,

Good Luck and Have Fun

Stream live video from camera on android

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.

Broadcasting Android Camera Video

I read (I think it was even on stackoverflow) that you can provide the MediaRecorder with a FileHandle of a TCP-Connection. Then you can listen to that connection, read the data, packetize it and resend it as a RTSP/RTP-Stream.

If I happen to find the original post, I'll reference it here.

EDIT:

The original Post was: Streaming Video From Android

And the part about the Filedescriptor is from: http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system

Just in case, I cite the according example from the blog:

String hostname = "your.host.name"; 
int port = 1234;
Socket socket = new Socket(InetAddress.getByName(hostname), port);
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
MediaRecorder recorder = new MediaRecorder(); // Additional MediaRecorder setup (output format ... etc.) omitted
recorder.setOutputFile(pfd.getFileDescriptor());
recorder.prepare();
recorder.start();

However this only sends the Video File Data over the wire. You can save it and then play it back. But as mentioned, it is not a stream, yet.

UPDATE:
You do not even have to use a TCP Socket for the first step. I just tripped over "LocalSocket"(1), that also gets you a FileHandle to feed the MediaRecorder. Those Local sockets are "AF_LOCAL/UNIX domain stream socket"s. See http://developer.android.com/reference/android/net/LocalSocket.html

I have not tried all the above myself as of today, but will pretty soon. So maybe I can be of more help in the near future :)

(1) LocalSocket is not usable on newer Android versions for security reasons! See Update from 2015-11-25.

UPDATE 2:
Just saw in the Android Sources the "OUTPUT_FORMAT_RTP_AVP". But it is hidden :( So I guess it will be available in future API versions of Android.
https://github.com/android/platform_frameworks_base/blob/master/media/java/android/media/MediaRecorder.java Line 219:

public static final int OUTPUT_FORMAT_RTP_AVP = 7;

I have not tried just tricking the hide by providing a hardcoded 7 ... If anybody does, please leave a comment here!

UPDATE 2015-11-25

I just ran into libstreaming: https://github.com/fyhertz/libstreaming
I did not look into it too deeply, but it seems there is a lot to be learned about streaming from Android from this project (if not only using it). I read there that the LocalSocket solution is invalid for newer Android versions :( But they present an alternative: ParcelFileDescriptor.



Related Topics



Leave a reply



Submit