Connection resetting from agent to USB Camera (transformed to RTSP stream)
See original GitHub issueI have an USB camera on my Lenovo laptop (running Fedora 35 Linux) and I ran RTSP Simple server according to this guide https://github.com/kerberos-io/camera-to-rtsp to expose it via RTSP as a container.
The command I used is:
podman run --rm --name rtsp-server --network=host -d --privileged -v $PWD/rtsp-simple-server.yml:/rtsp-simple-server.yml kerberos/rtsp-simple-server
File rtsp-simple-server.yml changed according to the doc, added lines:
paths:
usbcam:
runOnInit: ffmpeg -f v4l2 -i /dev/video0 -preset ultrafast -c:v libx264 -f rtsp rtsp://<MY_IP>:$RTSP_PORT/$RTSP_PATH
runOnInitRestart: yes
The server is working and I can connect to the camera using VLC and see live video without any interruptions.
Then I ran agent using latest docker image using this command:
podman run --rm --name kerberos -p 8081:80 -d kerberos/agent:latest
Both containers are running on the same host (Lenovo with Fedora).
The agent is working and accessible via port 8081, and I can successfully add camera in agent UI using URL rtsp://<MY_IP>:8554/usbcam - if I click Verify connection it saying Camera settings are successfully verified. However, the Live view doesn’t work - it shows nothing (only button Configure connection).
Also in the dashboard the message in IP camera frame is flipping from “Connected” to “Disconnected”
If I enable Continuous recording - then recording is happening - I see files available in Recordings - and each file has length 16-20 sec. It means agent can connect to the camera and do recordings, but looks like the connection is interrupting.
In rtsp-simple-server container I see following log messages:
2022/12/01 01:22:12 INF [RTSP] [conn <MY IP>:36654] opened
2022/12/01 01:22:12 INF [RTSP] [session 250958557] created by <MY IP>:36654
2022/12/01 01:22:12 INF [RTSP] [session 250958557] is reading from path 'usbcam', with TCP, 1 track (H264)
2022/12/01 01:22:36 INF [RTSP] [conn <MY IP>:36654] closed (read tcp <MY IP>:8554-><MY IP>:36654: read: connection reset by peer)
2022/12/01 01:22:36 INF [RTSP] [session 250958557] destroyed (not in use)
Looks like the connection between agent and rtsp server is resetting each ~20 sec.
But this is not happening for VLC connection, it stays for any period of time, for example, if I open streaming in VLC:
2022/12/01 01:31:08 INF [RTSP] [conn <MY IP>:39496] opened
2022/12/01 01:31:08 INF [RTSP] [session 284726513] created by <MY IP>:39496
2022/12/01 01:31:08 INF [RTSP] [session 284726513] is reading from path 'usbcam', with UDP, 1 track (H264)
It stays forever and finish only when I stop streaming in VLC with this message in logs:
2022/12/01 01:44:35 INF [RTSP] [session 284726513] destroyed (teared down by 1<MY IP>:39496)
2022/12/01 01:44:35 INF [RTSP] [conn <MY IP>:39496] closed (EOF)
Also I noticed in Agent container logs that machinery is restarting constantly:
{"level":"info","msg":"ProcessMotion: Motion detection enabled.","time":"2022-12-01T02:02:37+01:00"}
{"level":"info","msg":"ControlAgent: Number of packets read 3","time":"2022-12-01T02:02:40+01:00"}
{"level":"info","msg":"HandleStream: packet size 129966","time":"2022-12-01T02:02:41+01:00"}
{"level":"info","msg":"ControlAgent: Number of packets read 4","time":"2022-12-01T02:02:45+01:00"}
{"level":"info","msg":"ControlAgent: Number of packets read 4","time":"2022-12-01T02:02:50+01:00"}
{"level":"info","msg":"ControlAgent: Number of packets read 4","time":"2022-12-01T02:02:55+01:00"}
{"level":"info","msg":"ControlAgent: Number of packets read 4","time":"2022-12-01T02:03:00+01:00"}
{"level":"info","msg":"Main: Restarting machinery.","time":"2022-12-01T02:03:00+01:00"}
{"level":"info","msg":"ControlAgent: Number of packets read 4","time":"2022-12-01T02:03:00+01:00"}
{"level":"info","msg":"Main: Restarting machinery.","time":"2022-12-01T02:03:00+01:00"}
{"level":"info","msg":"RunAgent: waiting 3 seconds to make sure everything is properly closed.","time":"2022-12-01T02:03:01+01:00"}
{"level":"info","msg":"Successfully Opened config.json from opensource","time":"2022-12-01T02:03:04+01:00"}
{"level":"info","msg":"RunAgent: opening RTSP stream","time":"2022-12-01T02:03:04+01:00"}
{"level":"info","msg":"RunAgent: opened RTSP stream","time":"2022-12-01T02:03:04+01:00"}
{"level":"info","msg":"RunAgent: SetMaxGopCount was set with: 10","time":"2022-12-01T02:03:04+01:00"}
{"level":"info","msg":"ConfigureMQTT: not starting as running in Offline mode.","time":"2022-12-01T02:03:04+01:00"}
{"level":"info","msg":"HandleRecordStream: Start motion based recording ","time":"2022-12-01T02:03:04+01:00"}
{"level":"info","msg":"ProcessMotion: Motion detection enabled.","time":"2022-12-01T02:03:04+01:00"}
{"level":"info","msg":"HandleStream: packet size 84577","time":"2022-12-01T02:03:06+01:00"}
{"level":"info","msg":"ControlAgent: Number of packets read 5","time":"2022-12-01T02:03:07+01:00"}
{"level":"info","msg":"ControlAgent: Number of packets read 5","time":"2022-12-01T02:03:12+01:00"}
{"level":"info","msg":"ControlAgent: Number of packets read 5","time":"2022-12-01T02:03:17+01:00"}
{"level":"info","msg":"ControlAgent: Number of packets read 5","time":"2022-12-01T02:03:22+01:00"}
{"level":"info","msg":"Main: Restarting machinery.","time":"2022-12-01T02:03:22+01:00"}
{"level":"info","msg":"RunAgent: waiting 3 seconds to make sure everything is properly closed.","time":"2022-12-01T02:03:23+01:00"}
Troubleshooting Done docker image kerberos/agent:latest I tried to run agent on separate RPI4 host - and I’m having the same issue (USB camera on Lenovo Laptop and agent on RPI) - connection resetting after ~20 sec.
Host Specs: Lenovo T260 with Fedora 36 + podman + USB camera Agent tested also on RPI4 with Ubuntu 22.04
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top GitHub Comments
Comment just to confirm that solution is working. I changed the value to 60 and command is
runOnInit: ffmpeg -f v4l2 -i /dev/video0 -preset ultrafast -c:v libx264 -x264-params keyint=60:scenecut=0 -f rtsp rtsp://<my_ip>:$RTSP_PORT/$RTSP_PATH
Camera + agent have been working with no issues for more than 24 hours, recording/motion detection works. Thank you @cedricve !Modified the configuration file, thanks for reporting. I changed force keyint to 60, not sure if you experimented with that as well. Feel free to reopen this issue if anymore problems @vadimzharov .