1

On my Android client, I have the path of a file on my Java server:

serverVidPathString;

How can I make it so I can stream the server's file using RTSP to the client?

Example for the client code:

urlVid = "rtsp://"+serverVidPathString;
Uri video = Uri.parse(urlVid);
videoView.setVideoURI(video);
videoView.start();
James
  • 71
  • 3

1 Answers1

1

RTSP (Real Time Streaming protocol) just used to set up and control the streaming session.

It allows the client and the server describe the stream and the types of stream the client can play, and also allows the client issue commands like Play, Pause etc.

The actual media, video in your case, is not sent over RTSP - it is sent via a separate transport protocol such as RTP (Real Time Transport Protocol).

Taking a step back, if your video is a static video file, i.e. not a live stream, you may find it easier to simply use HTTP streaming to serve the file, or if you really need it one of the ABR (Adaptive Bit Rate) protocols, although the complexity rises here again.

You can set up a very simple static server using node to test this and then test the URL from this simple server in your Android app - there are several examples available such as:

You will want to make sure that 'acceptRanges' option is set to true - this allows the client to download the video chunk by chunk so it can tart playback immediately, rather than wait for the whole file to download.

Mick
  • 24,231
  • 1
  • 54
  • 120
  • Thank you for the detailed response! Much clearer now. I do need to livestream the file though, so my question still stands... – James Apr 25 '18 at 15:49
  • Just a quick check - you mention a file in your question, which would not normally be a live stream? Assuming, it is a live stream, then you can actually still use HTTP ABR protocols like HLS and DASH. You can see examples here: https://developer.bitmovin.com/hc/en-us/articles/115001080274-Create-a-Livestream-with-our-API and here: https://www.elemental.com/products/aws-elemental-live – Mick Apr 25 '18 at 16:19
  • The examples in the comment above are getting more complex though and these are paid examples, although open source steaming platforms do exist also. – Mick Apr 25 '18 at 16:20
  • If you want an example of RTP streaming, this is a good one to look at: https://www.wowza.com/docs/how-to-set-up-live-streaming-using-an-rtsp-rtp-based-encoder – Mick Apr 25 '18 at 16:25
  • Thanks for the links Mick, they seem like really good solutions. I suppose I should have clarified though, I'm trying not to use any paid solutions. My bad. I'm kinda new to Android (though eager to learn!) so I'm also trying to keep it as simple as reasonably possible, at least on the complex protocol implementation front... The file would usually not be a a stream of its own, but just a file on an Android device. The streaming part is what I'm trying to figure out. – James Apr 25 '18 at 16:30
  • Ok - will the original file be on android, on the server, or will it actually be a live steam from a camera or from some external source? – Mick Apr 26 '18 at 09:53
  • The original file will be on the server (my mistake in my last comment, sorry). A downloaded movie, for example. – James Apr 26 '18 at 10:19
  • In that case the NPM static serve example above should work fine - its very easy to test, just set up and run their example on your machine, put the video in the appropriate folder and then put the URLof your machine (which can be your laptop so long as the phone can connect) and it should stream fine. The video does need to be a format that the phone can handle, but you can test with some example mp4 videos to check. – Mick Apr 26 '18 at 10:23
  • Are you referring to the paid solutions? I'm kinda trying to avoid paid solutions if possible, is there a free way to do this? – James Apr 26 '18 at 12:16
  • No the NPM example above is not a paid solution - it is very basic static streaming but it could be good enough for your needs, and is very easy to test. – Mick Apr 26 '18 at 12:35
  • Alright, thank you very much! I'll try it out as soon as I can and see if it works. Some silly follow up questions until then (if you feel like answering :)): does enabling `acceptRanges` make it (practically) an HLS server, since it divides the file to chunks? Would I be able to simply stream the file into a video view (`videoView.setVideoURI(Uri.parse("http://"+serverAddressAndPort`))? And lastly, assuming there's only 1 client, is there anything I can do to reduce latency? Thanks again! – James Apr 26 '18 at 12:58
  • accepRanges only allows the file be downloaded in chunks so you can start playing asap, but it is not ABR like HLS which is a bit more involved - see here: https://stackoverflow.com/a/42365034/334402. Yes, you should be able to stream into a videoview. Reducing lately - ABR is actually good here as you can start up with a low bandwidth and then move to the best one your connection will support - see answer linked at the start of this comment. – Mick Apr 27 '18 at 10:10
  • It works! Thank you very much Mick, I appreciate it! The latency was quite high though so I'm gonna try implementing the same thing but with UDP (I wonder why most streaming services don't do this?). I tried reading the code for some premade ABR implem's and I didn't understand it, so I'm gonna try writing my own implementation for that as well. If I understand correctly from the post you sent, I just need to create several versions of the same N seconds chunk. Then according to the latency I send the appropriate chunk. Do you know how to downgrade the chunk's quality for this? Thanks again! – James Apr 29 '18 at 09:24
  • HTTP is generally used more than UDP, partly, if not mainly, because it has a greater chance of getting through firewalls etc - UDP is often blocked or restricted. One thing to check is that your file, if it is an mp4 file, is set up with the MOOV header at the start - see here: https://gist.github.com/alienresident/8949291 – Mick Apr 30 '18 at 10:56