question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connection resetting from agent to USB Camera (transformed to RTSP stream)

See original GitHub issue

I 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:closed
  • Created 10 months ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
vadimzharovcommented, Dec 3, 2022

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 !

0reactions
cedricvecommented, Dec 3, 2022

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 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Browser-based WebRTC stream from RTSP IP camera with ...
To broadcast a stream, from the IP camera in the interleaved mode you only need to open or redirect one RTSP port of...
Read more >
AlexxIT/go2rtc - GitHub
Ultimate camera streaming application with support RTSP, WebRTC, HomeKit, FFmpeg, RTMP, ... camera snapshot link, can be converted by go2rtc to MJPEG stream...
Read more >
How to connect to RTSP streams on Arecont cameras
Download VLC from HERE. Click on Media and select Open network stream vlc1.JPG; Copy and paste the syntax RTSP stream you wish to...
Read more >
Agent DVR Editing Cameras - iSpy
Click on the Server icon at the top left of the Agent UI and "Edit Devices" under Devices. Choose the device you want...
Read more >
Troubleshooting video units and cameras in Security Center
There are several possible causes for a missing video error: The network is slow. Port connection has issues. The video stream was dropped...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found