I am trying to get a live RTSP feed from a webcam to display on a website. I have a Linux server I am running gstreamer
on and I am using hls.js
to serve the feed up. I have followed a number of examples out there, but nothing I try can get this working across all browsers/devices. Here's what I have right now, and the results I am seeing.
Gstreamer config This is my gstreamer script - I suspect the issue might be here with encoding settings, but I'm not sure what to try:
#!/bin/bash
gst-launch-1.0 -v -e rtspsrc protcols=tcp location=rtsp://XXX.XXX.XXX.XXX:XXXX/user=USER_password=PASSWORD_channel=1_stream=0.sdp?real_stream ! queue ! rtph264depay ! h264parse config-interval=-1 ! mpegtsmux ! hlssink location="%06d.ts" target-duration=5
index.html Here is the webpage serving the feed up:
<!DOCTYPE html>
<head>
<title>Live Cam Test</title>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
</head>
<body>
<video id="video" controls="controls" muted autoplay></video>
<script>
if (Hls.isSupported()) {
var video = document.getElementById('video');
var hls = new Hls();
// bind them together
hls.attachMedia(video);
hls.on(Hls.Events.MEDIA_ATTACHED, function () {
console.log("video and hls.js are now bound together !");
hls.loadSource("http://ServerName/live/playlist.m3u8");
hls.on(Hls.Events.MANIFEST_PARSED, playVideo);
});
}
</script>
</body>
</html>
Currently, this setup works the best in Chrome on Windows. The video is loaded, it autoplays, and it loads new segments as it plays, although it does seem to pause for a few seconds here and there and eventually gets a bit behind the live video.
On iOS devices, I cannot browse to the index.html
page, I need to navigate directly to the playlist.m3u8
file. Once I do that, it appears to work pretty well.
On OSX, it doesn't appear to work in any browser...tried Chrome, Safari, Brave... I get weird results, sometimes it loads a single frame of the video and stops, sometimes it doesn't load anything.
I have tried the tutorials and code examples from hls.js's documentation and still no dice, so I think I must be doing something wrong in my gstreamer setup. Any help is much appreciated!