Simon
Simon

Reputation: 3730

Best way to stream audio and video from an Android phone to a RTMP server

I'm looking for the best way to stream video and audio from an Android phone to a server using RTMP. I've spent some time on this problem and this far I've been able to stream video only using FFMPEG. There are many ways to build the lib for Android and I guess that with some more work I should be able to stream Audio too.

The thing is that I need to encode the video in h264 and the audio in AAC, and it would be very easy to do it using Android's MediaRecorder. So I started looking for a RTMP library for Android and found this Red5 port that seems to be working pretty well. Using it I can stream a video file stored on the phone very easily, and the audio is working too.

So my question is the following: Is there a way to connect Android's MediaRecorder output to the RTMP library? I guess the way would be to 'fake' a file in setOutputFile(), and then to send the data to the RTMP encoding methods, but I can't figure a way to do it.

Any clue is welcome, really. Thanks in advance.

Upvotes: 4

Views: 4045

Answers (2)

MACMAN
MACMAN

Reputation: 1971

May be using Red5 Media server can help you. There are working examples that comes with it which you can use for streaming purpose.

Upvotes: 0

Rich
Rich

Reputation: 1055

you are able to write the data to a FileDescriptor instead of a file with setOutputFile().

FileDescriptor fd = mLocalSender.getFileDescriptor();
mRecorder.setOutputFile(fd);

so you can stream the data to a socket. to get the data from this socket looks like this:

mLocalServer = new LocalServerSocket(LOCAL_SOCKET_ADDRESS);

mLocalReceiver = new LocalSocket();
mLocalReceiver.connect(new LocalSocketAddress(LOCAL_SOCKET_ADDRESS));

mLocalSender = mLocalServer.accept();

if (mLocalReceiver != null)
{
    mInputStream = mLocalReceiver.getInputStream();
}

i don't know how your RTMP library is working, but i think, it should be possible to pass the input stream to some methods of the library.

for further information you also can check out the spydroid application. it includes a lot of useful stuff for video streaming over RTP without any special streaming libraries.

Upvotes: 2

Related Questions