I have already done proper research, but still lack information on the thing I would like to achieve.
So I would like to program an application where the user can record a video and instantly (live) upload the video to a RTP/RTSP Server. The server side will not be a problem. The thing I am unclear about is how to achieve this on the phone-side.
My research so far is that I have to write the video on recording to a local socket rather than to a file, because the 3gp files if written to a file cannot be accessed, until finalized (when the video is stopped and the header information have been written to the video about length and others).
When the socket receives the continuous data, I will need to wrap it into a RTP packet and send it to the remote server. I possibly will also have to do basic encoding first (which is not so important yet).
Does anybody have any idea, if this theory is correct so far. I would also like to know if someone could point me to a few code-snippets of similar approaches, especially for sending the video on the fly to the server. I am not sure yet how to do that.
Thank you very much and best regards
At this point, if i had to accept camera ( raw stream ) and immediately make it available to a set of clients, i would go the google hangouts route and use WebRTC. see ondello 'platform section' for the toolset/SDK. During your evaluation, you should have looked at comparative merit of WebRTC v RTSP.
IMO with its statefulness, RTSP will be a nightware behind firewalls and with NAT. AFAIK on 3G/4G the use of RTP in 3rd party apps is a bit risky.
That said, i put up on git an old android/rtp/rtsp/sdp project using libs from netty and 'efflux'. I think that this project was trying to retrieve and play just the audio track within the container ( vid track ignored and not pulled via network ) from Youtube videos all of which were encoded for RTSP at the time. I think there were some packet and frame header issues and i got fed up with RTSP and dropped it.
If you must pursue RTP/RTSP some of the packet and frame level stuff that other posters have mentioned is right there in the android classes and in the test cases that come with efflux
is there a reason for using 3gp on the client side? With mp4 (with MOOV atom set in header) you can read the temp file in chunks and send over to the server, there will likely be a slight time delay though, all depends on your connection speed as well. Your rtsp server should be able to re-encode the mp4 back to 3gp for low bandwidth viewing.
Check this answer: Video streaming over WIFI?
Then if u want to see the live streaming in android phone then include vlc plugin inside your application and connect through real time streaming protocol(rtsp).
If u have installed VLC on your android phone, then you can stream using intent and pass the ip address and port no as shown above.
And here is rtsp session class. It uses rtsp socket to talk to media server. Its purpose is also to hold session params, such as, what streams it can send (video and/or audio), queues, somewhat audio/video sync code.
Used interface.
Session itself.
I tried to achieve the same result (but abandoned due to lack of experience). My way was to use ffmpeg and/or avlib because it already has working rtmp stack. So in theory all you need is to route video stream to ffmpeg process which will stream to server.
Your overall approach sounds correct, but there are a couple of things you need to consider.
Sending frames in real-time over RTP/RTCP is the correct approach. As the capture device captures each frame, you need to encode/compress it and send it over the socket. 3gp, like mp4, is a container format used for file storage. For live capture there is no need to write to a file. The only time this makes sense is e.g. in HTTP Live Streaming or DASH approaches, where media is written to a transport stream or mp4 file, before being served over HTTP.
I would disagree, encoding is very important, you'll likely never manage to send the video otherwise, and you'll have to deal with issues such as cost (over mobile networks) and just the sheer volume of media depending on resolution and framerate.
Take a look at the spydroid open source project as a starting point. It contains many of the necessary steps including how to configure the encoder, packetise to RTP, send RTCP, as well as some RTSP server functionality. Spydroid sets up an RTSP server so media is encoded and sent once an RTSP client such as VLC is used to setup an RTSP session. Since your application is driven by the phone user wanting to send media to a server, you may need to consider another approach to start the sending, even if you send some kind of message to the server to for instance setup an RTSP session like in spydroid.