deepch / RTSPtoWeb

RTSP Stream to WebBrowser
MIT License
1.33k stars 314 forks source link

Only HLS works #87

Open xiki808 opened 2 years ago

xiki808 commented 2 years ago

For both my cameras I see no proper stream in MSE and WebRTC, but works fine with HLS.

For MSE, the camera loads, but just after a few seconds it get stuck and I see this error:

ERRO[2022-02-14T21:32:02+01:00] stream no video                               call=ErrorStreamNoVideo channel=0 func=HTTPAPIServerStreamMSE module=http_mse stream=5171db18-46f0-4b20-ba1f-a64ace0b26c9
ERRO[2022-02-14T21:32:02+01:00] read tcp 127.0.0.1:8083->127.0.0.1:55972: use of closed network connection  call=Receive channel=0 func=HTTPAPIServerStreamMSE module=http_mse stream=5171db18-46f0-4b20-ba1f-a64ace0b26c9
ERRO[2022-02-14T21:32:02+01:00] <nil>                                         call=Close channel=0 func=HTTPAPIServerStreamMSE module=http_mse stream=5171db18-46f0-4b20-ba1f-a64ace0b26c9
INFO[2022-02-14T21:32:02+01:00] Client Full Exit

For WebRTC the camera never loads, and a loading indicator is shown

ERRO[2022-02-14T21:30:16+01:00] stream no video                               call=ErrorStreamNoVideo channel=0 func=HTTPAPIServerStreamWebRTC module=http_webrtc stream=9f6de91a-2745-4c24-ad77-5b22ca8b25b2
2022/02/14 21:30:23 [OPTIONS rtsp://10.0.0.101:554/onvif1 RTSP/1.0
CSeq: 5
Require: implicit-play
User-Agent: Lavf58.76.100
Session: 1a1078f9

]
ERRO[2022-02-14T21:30:26+01:00] stream no video                               call=ErrorStreamNoVideo channel=0 func=HTTPAPIServerStreamWebRTC module=http_webrtc stream=9f6de91a-2745-4c24-ad77-5b22ca8b25b2
2022/02/14 21:30:49 [OPTIONS rtsp://10.0.0.101:554/onvif1 RTSP/1.0
CSeq: 6
Require: implicit-play
User-Agent: Lavf58.76.100
Session: 1a1078f9

]

Am I missing something with camera configurations or is this a bug?

xiki808 commented 2 years ago

It works for a while actually, I have installed it outside the container and it's ok. Not sure what makes webRTC not work in an LXC container.

It still crashes in a few seconds with the following error, running on a raspberry pi 4

ERRO[2022-02-14T21:22:11Z] stream no video                               call=ErrorStreamNoVideo channel=0 func=HTTPAPIServerStreamWebRTC module=http_webrtc stream=a155ebd1-a516-4b1b-b215-b73151322694
2022/02/14 21:22:11 [OPTIONS rtsp://10.0.0.101:554/onvif1 RTSP/1.0
CSeq: 12
Require: implicit-play
User-Agent: Lavf58.76.100
Session: 3b5fc8e2

]
deepch commented 2 years ago

share you camera stream and send me url

xiki808 commented 2 years ago

Thank you for your interest! Sent you my streams by email

luzik commented 2 years ago

I can confirm this issue. I was using @allenporter ghcr.io/allenporter/amd64-rtsp-to-web:latest. Out of container it working fine.

deepch commented 2 years ago

need update?

xiki808 commented 2 years ago

I'm using HomeAssistant core setup, so not using the addon. But so it doesn't work for the addon as well @luzik? Was tempted to try out Docker setup once I have time.

I haven't tried on Docker, but had issues having websocket stream in an LXC container.

allenporter commented 2 years ago

I'm not sure how Lxc container, works but assuming it's like docker is there a motion of opening or using the host network? HLS uses everything over http however webrtc needs, for example, some udp ports opened up.

xiki808 commented 2 years ago

I think this can be the issue, that I didn't forward the right ports, I started by having a clue at what ports I need from here

I have pulled the latest changes just now and tested the stream and these are my results running on the host Raspberry PI

Stream URL used: rtsp://xxx:xxx@10.0.0.13:5541/Streaming/Channels/101/ rtsp_port used in config.json: 5541

In Play webrtc video page: Stream loads fine but breaks after a few seconds

Logs from page load till stream breaks:

ERRO[2022-02-19T14:27:21Z] WebRTC Client Offline                         call=WritePacket channel=0 func=HTTPAPIServerStreamWebRTC module=http_webrtc stream=d342e19a-5894-4094-a492-3b23c07c2b54
2022/02/19 14:27:23 [OPTIONS rtsp://10.0.0.13:5541/Streaming/Channels/101/ RTSP/1.0
CSeq: 22
Authorization: Digest username="admin", realm="IP Camera(E3293)", nonce="dd393a305d1ba08f9d088f3f720ee0e3", uri="rtsp://10.0.0.13:5541/Streaming/Channels/101/", response="b522cd05187b79e94073e8ff34798655"
Require: implicit-play
User-Agent: Lavf58.76.100
Session: 1891054719

]
2022/02/19 14:27:23 [OPTIONS rtsp://10.0.0.13:5541/Streaming/Channels/101/ RTSP/1.0
CSeq: 22
Authorization: Digest username="admin", realm="IP Camera(E3293)", nonce="2dc706f9f54322a04a954f203162f7f7", uri="rtsp://10.0.0.13:5541/Streaming/Channels/101/", response="d1b3c27f82095bc5f8484d002c5a7229"
Require: implicit-play
User-Agent: Lavf58.76.100
Session: 1816203257

]
ERRO[2022-02-19T14:27:33Z] stream no video                               call=ErrorStreamNoVideo channel=0 func=HTTPAPIServerStreamWebRTC module=http_webrtc stream=d342e19a-5894-4094-a492-3b23c07c2b54

In Play mse video: Stream loads but breaks after a few seconds

Logs from page load till stream breaks:

ERRO[2022-02-19T14:26:26Z] EOF                                           call=Receive channel=0 func=HTTPAPIServerStreamMSE module=http_mse stream=d342e19a-5894-4094-a492-3b23c07c2b54
ERRO[2022-02-19T14:26:26Z] Client Reader Exit                            call=controlExit channel=0 func=HTTPAPIServerStreamMSE module=http_mse stream=d342e19a-5894-4094-a492-3b23c07c2b54
ERRO[2022-02-19T14:26:26Z] <nil>                                         call=Close channel=0 func=HTTPAPIServerStreamMSE module=http_mse stream=d342e19a-5894-4094-a492-3b23c07c2b54
INFO[2022-02-19T14:26:26Z] Client Full Exit
2022/02/19 14:26:31 [OPTIONS rtsp://10.0.0.13:5541/Streaming/Channels/101/ RTSP/1.0
CSeq: 20
Authorization: Digest username="admin", realm="IP Camera(E3293)", nonce="dd393a305d1ba08f9d088f3f720ee0e3", uri="rtsp://10.0.0.13:5541/Streaming/Channels/101/", response="b522cd05187b79e94073e8ff34798655"
Require: implicit-play
Session: 1891054719
User-Agent: Lavf58.76.100

]
2022/02/19 14:26:31 [OPTIONS rtsp://10.0.0.13:5541/Streaming/Channels/101/ RTSP/1.0
CSeq: 20
Authorization: Digest username="admin", realm="IP Camera(E3293)", nonce="2dc706f9f54322a04a954f203162f7f7", uri="rtsp://10.0.0.13:5541/Streaming/Channels/101/", response="d1b3c27f82095bc5f8484d002c5a7229"
Require: implicit-play
User-Agent: Lavf58.76.100
Session: 1816203257

]
ERRO[2022-02-19T14:26:44Z] stream no video                               call=ErrorStreamNoVideo channel=0 func=HTTPAPIServerStreamMSE module=http_mse stream=d342e19a-5894-4094-a492-3b23c07c2b54
ERRO[2022-02-19T14:26:44Z] read tcp 10.0.0.4:8083->10.0.0.6:62776: use of closed network connection  call=Receive channel=0 func=HTTPAPIServerStreamMSE module=http_mse stream=d342e19a-5894-4094-a492-3b23c07c2b54
ERRO[2022-02-19T14:26:44Z] <nil>                                         call=Close channel=0 func=HTTPAPIServerStreamMSE module=http_mse stream=d342e19a-5894-4094-a492-3b23c07c2b54
INFO[2022-02-19T14:26:44Z] Client Full Exit

All fine with HLS

When running in container same results except that WebRTC never loads. I have opened port 5541 and 8083 both TCP and UDP.

allenporter commented 2 years ago

How about when using host network? That config file you pointed to is using the host network.

deepch commented 2 years ago

As I understand it, the issue here is with the port forwarding of the container and not with the project as a whole?

deepch commented 2 years ago

If you have an example how to do it I can do it.

deepch commented 2 years ago

can i read ports from flags or global variables (ENV) or can i do

1) local storage of the configuration file not in the container

2) on startup, extract the ports from the config file and add them to the docker startup keys

xiki808 commented 2 years ago

My issues are two actually, 1. that it's not working on container with the setup I configured and 2. the installation on the host webrtc and mse streams stop like after 5 seconds

In my previous comment I was testing directly on the host and comparing the results to that of the container.

@deepch if you are interested to setup an LXC container you can follow the below. Keep in that I'm using a Raspberry Pi running on Raspbian debian 11 with LAN IP 10.0.0.4

Install LXD

apt-get snapd
snap install core
snap install lxd

Setup LXD

lxd init

Setup inputs...

expect "Would you like to use LXD clustering?"
send -- "\r"
expect "Do you want to configure a new storage pool?"
send -- "\r"
expect "Name of the new storage pool"
send -- "\r"
expect "Name of the storage backend to use"
send -- "\r"
expect "Create a new BTRFS pool?"
send -- "\r"
expect "Would you like to use an existing empty block device"
send -- "\r"
expect "Size in GB of the new loop device"
send -- "\r"
expect "Would you like to connect to a MAAS server?"
send -- "\r"
expect "Would you like to create a new local network bridge?"
send -- "\r"
expect "What should the new bridge be called?"
send -- "\r"
expect "What IPv4 address should be used?"
send -- "10.0.1.1/24\r"
expect "Would you like LXD to NAT IPv4 traffic on your bridge?"
send -- "\r"
expect "What IPv6 address should be used?"
send -- "none\r"
expect "Would you like the LXD server to be available over the network?"
send -- "\r"
expect "Would you like stale cached images to be updated automatically?"
send -- "\r"
expect "Would you like a YAML \"lxd init\" preseed to be printed?"
send -- "\r"

Create two yaml files:

container.yaml

config:
  boot.autostart: true
  boot.autostart.delay: 5
  environment.TZ: Europe/Malta
description: ""
devices:
  root:
    path: /
    pool: default
    type: disk
name: container
used_by: []

webrtc.yaml (here is where the port forwarding is configured - the machine should have these ports free) You will need to change the listen IP accordingly. The network's interface lxdbr0 should be the same.

config:
  boot.autostart.priority: "8"
description: ""
devices:
  eth0:
    ipv4.address: 10.0.1.25
    name: eth0
    network: lxdbr0
    type: nic
  proxy5541UDP:
    connect: udp:127.0.0.1:5541
    listen: udp:10.0.0.4:5541
    type: proxy
  proxy5541:
    connect: tcp:127.0.0.1:5541
    listen: tcp:10.0.0.4:5541
    type: proxy
  proxy8083:
    connect: tcp:127.0.0.1:8083
    listen: tcp:10.0.0.4:8083
    type: proxy
  proxy8083UDP:
    connect: udp:127.0.0.1:8083
    listen: udp:10.0.0.4:8083
    type: proxy
name: webrtc
used_by: []

Create LXD profiles

cat .container.yaml | lxc profile edit container
cat .webrtc.yaml | lxc profile edit webrtc

Launch the container

lxc launch images:debian/11/armhf webrtc -p container -p webrtc
lxc exec webrtc bash

.. to get in the container

Let me know if you are interested and need any more info

luzik commented 2 years ago

I'm using HomeAssistant core setup, so not using the addon. But so it doesn't work for the addon as well @luzik? Was tempted to try out Docker setup once I have time.

I haven't tried on Docker, but had issues having websocket stream in an LXC container.

No, my setup is home assistant in docker no hass, no addons. So this is probably only issue with port forwarding, or I have outdated docker image (Version: 2022-02-19 16:51:00.446258043)

My docker-compose

homeassistant:
    container_name: homeassistant
    image: homeassistant/home-assistant:stable
    environment:
      - TZ=Europe/Warsaw
    restart: unless-stopped
    ports:
      - 8123:8123
    depends_on:
      - influxdb
      - mosquitto
      - mariadb
        #- glances
      - shinobi
      - motioneye
    volumes:
      - ~/ha/homeassistant:/config
    devices:
      - /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0:/dev/ttyUSB0

  rtsp-to-web:
    image: ghcr.io/allenporter/amd64-rtsp-to-web:latest
    container_name: rtsp-to-web
    restart: unless-stopped
    ports:
      - 8230:8083
      - 5541:5541
      - 5353:5353

As you can see those ports are exposed and webrtc do not work

allenporter commented 2 years ago

I've added a docker example: https://github.com/deepch/RTSPtoWeb#installation-from-docker -- you need to use host network. Edit: or rather, using host network works, maybe other port configurations work but i'm not sure what they are yet. I believe you're making incorrect assumptions about the requirements for what ports need to be exposed. Edit: Also, i realize there are multiple conversations here, so we may want to fork the discussion

xiki808 commented 2 years ago

@allenporter with using the host network, you mean not to use a virtual bridge interface setup at the host ( used for containers ), but to use the host physical network interface?

allenporter commented 2 years ago

I don't know the LXC details, but if you're relying on forwarding individual ports you may not be getting everything.

luzik commented 2 years ago

I believe that we are talking about same issue. @xiki808 just using different virtualization. If ports generated for webrtc are random, then lxc will need bridge mode because I don't know --network host lxc substitute. For docker this option is working fine.

@allenporter please add docker-compose example to your documentation


  rtsp-to-web:
    image: ghcr.io/allenporter/amd64-rtsp-to-web:latest
    restart: unless-stopped
    network_mode: host
xiki808 commented 2 years ago

I see, ok thanks guys, will see what I can do for LXC there and will post here once I find something.

Do you have any suggestions why my webrtc and mse are stopping after just a few settings? This I can observe when I setup this project on the host system.

xiki808 commented 2 years ago

For more info regarding stream stopping after few seconds, in browser console I find this log: image

Would really appreciate any guidance on this!

LiangHuangBC commented 1 year ago

Any progress on this issue, I got same issue when connect to internet by IPV6, only HLS works.