deepch / RTSPtoWeb

RTSP Stream to WebBrowser
MIT License
1.16k stars 283 forks source link

Can i stream my rtsp cam on my website ? or only on the rtsptoweb ? #431

Closed tyrelire closed 3 months ago

tyrelire commented 5 months ago

I want to stream my rtsp ip cam on my website can I ?

Vukodlak7 commented 4 months ago

Yes, that is exactly what this container is made for... Problem is, the instructions are pretty rough in my opinion. here is what I did: (everyone feel free to show me a better way)

you need to mount the config file for the container outside so you can edit it and the changes will stick.

mkdir /home/vukodlak/configs/webrtc (make a directory wherever you want to store the config.json) cd /home/vukodlak/configs/webrtc (change to new directory) touch config.json (you have to create the file first otherwise it tries to create a directory)

Stack config command for portainer:

version: '3.8'

services: rtsp-to-web: image: ghcr.io/deepch/rtsptoweb:latest container_name: rtsp-to-web network_mode: host volumes:

Now you can fire up the container and connect on port 8083 of the server and setup your streams

Here is the part that drove me nuts: There is no way to just right click on a stream and get the address to use for your webpage that I could find anywhere. There is a list of endpoints for each stream here in the docs, but the stream ID was impossible to find. Example: endpoints: [https://github.com/deepch/RTSPtoWeb/blob/master/docs/api.md#video-endpoints]

so webrtc endpoint is: /stream/{STREAM_ID}/channel/{CHANNEL_ID}/webrtc

http://127.0.0.1:8083/stream/{STREAM_ID}/channel/{CHANNEL_ID}/webrtc

open your config.json and inside are the streams you created:

"streams": { "sideyardcam": { "name": "test video stream 1", "channels": { "0": { "name": "ch1", "url": "rtsp://192.168.1.122:554/live/ch0", ......etc etc etc .....

the name is NOT the stream ID! it is the sideyardcam in this case if you made your own config file or if you used the web interface defaults it is a big long bunch of characters

so, the url to display your webcam on your webpage in this case is: http://192.168.1.100:8083/stream/sideyardcam/channel/0/webrtc

so to further confuse things...not all browsers support webrtc or HLS or whatever, so going straight to that address in your browser WON'T work. You need to use the html code in the examples that are listed in the docs. That will set up a REALLY nice player that you can put into your html code for your webpage. :)

HDTS1 commented 4 months ago

I just spend a day discovering all the things you wrote here. I really should have checked Issues first. Lol. The only thing left is to secure the streams. wonder how that could be done.

Vukodlak7 commented 4 months ago

yeah, I was hoping this would save somebody else the pain I went through haha I didn't look into securing it cause I didn't care. It isn't exposed to the WAN

HDTS1 commented 4 months ago

is the stream url giving you the stream? I am getting 404...

Vukodlak7 commented 4 months ago

you cant view it in a browser by itself. Browsers wont display a webrtc stream without some kind of player.

heres the entire code section

rtccode.txt

HDTS1 commented 4 months ago

Thanks man, that make sense. It really could use better documentation. Coming from mediamtx, I was very confused.

Vukodlak7 commented 4 months ago

one last thing. if you set the camera to on-demand, or whatever its called, it will beat your server to death. Set to persistent and I am running 2 rtsp/webrtc cameras with only using like 2% cpu because there is no transcoding going on... Have fun!

Wolfleader101 commented 4 months ago

Has anyone been able to get HTTPS working with this lib? Got it all setup but even when I enable HTTPS in the config it does nothing

madroots commented 4 months ago

I use reverse proxy for https, isnt that an option for you?

Wolfleader101 commented 4 months ago

I use reverse proxy for https, isnt that an option for you?

I have tried that but I keep getting

[chromium] [ERROR:ssl_client_socket_impl.cc(974)] handshake failed; returned -1, SSL error code 1, net_error -107
[chromium] [ERROR:ssl_client_socket_impl.cc(974)] handshake failed; returned -1, SSL error code 1, net_error -107
madroots commented 4 months ago

Dont enable https on rtsptoweb though.

Basically it should work as is without configuration. Only add cameras and reverse proxy record. See if it works and then configure further. I use caddy proxy, very simple to use.

tyrelire commented 3 months ago

thank you very much I didn't know all that I will be able to have a little fun improving my web application for my cameras