Daniel
Daniel

Reputation: 2592

Modern way of displaying RTSP H264 stream in a browser (HTML5)

Yes, this topic keeps popping up from time to time also here on SO.

I've read a lot about this topic and also tried some solutions but I have some constraints:

  1. browser-independency (most browsers should work)
  2. platform-independent (major platforms should be supported)
  3. work out-of-the-box (no plugins!)
  4. low latency (preferred under 1 sec)
  5. bandwidth is limited (MJPEG is not an option)
  6. no transcode!

So going forward: an H264 stream seems perfect for constraints 1 and 2.

Also my source produce a live H264 (to be exact: MPEG-4 AVC, part 10) into an RTSP container.

But RTSP is still not supported in browser.

What I've checked:

All the posts above are related to this question, and a lot of valuable information was there.

Also I've read a very good article from 2014 (!) which is detailed and quite forward-looking.

So, as of today, the best solution would be this:

  1. parse the RTSP and extract the h264 stream
  2. restructure the stream (convert it to fragmented MP4)
  3. websocket (see later)
  4. fMP4 can be easily played by HTML5 video if the browser has the MSE (alternative is to use broadway.js that is cool but CPU intensive)

There are solutions where the step 1 and 2 happens on server side, then the fMP4 is pushed into a websocket. The client consumes the data from websocket and pass it to MSE components for displaying.

The article from 2014 shows that step2 can also happen on client side. In this case only step 1 happens on the server, then h264 is pushed into the websocket, and on the client side there is the restructuring and displaying of course.

Streamedian seemed a good solution for the first sight, but they doesn't publish their server side codes, and also their site returned with 502 error for a day.

I don't want to use GStreamer or ffmpeg, they are both too heavy.

However there are nice items which can help:

Going back to my list, step2 can be done with MP4Box - at least I believe / hope.

Step3 and step4 are straightforward, there are tons of howtos on these ones.

However I'm a bit puzzled with step1. It shall be done on server side, preferably in a language which can interact with websockets easily (like java).

That is the point of my question: I need to extract the h264 stream from RTSP in java, how can I do it simple but without calling external programs?

Upvotes: 15

Views: 22198

Answers (1)

nik0x1
nik0x1

Reputation: 1343

I hope WebRTC is what you are looking for.

WebRTC is supported by most browsers.

Upvotes: 0

Related Questions