keshavdv / unifi-cam-proxy

Enable non-Ubiquiti cameras to work with Unifi NVR
MIT License
1.71k stars 237 forks source link

Broken Pipe error when low FPS #194

Closed nicoleise closed 2 years ago

nicoleise commented 2 years ago

Describe the bug FFMPEG seems unable to stream to Unifi Protect when FPS are lower than 15. Exits with broken pipe error. I only have access to Dahua cams but can reliably reproduce the error across five cams (two different models and resolutions) and I guess this will be the same regardless of source. The requirement for FPS seems to be nowhere in the documentation?

With lower FPS, I could not get one camera working, now I have five LXCs each streaming a camera to Unifi Protect, and while live view can occasionally skip a second on the live view view (with all cameras shown), recordings look perfect. Mentioning this to say that any ressource issue is unlikely.

This also limits using sub-streams and such on Dahua cams, as only the main stream can go as high (30 FPS on my HD cams, 15 is max on my 4K cams). The sub streams for 1080p are max 6 FPS.

Install Method/Host Machine I've setup an LXC on ProxMox with an Alpine Linux template, and then manually installed python and pip and further manually "executed" the relevant content of the dockerfile-amd64 to match dependencies. Note, that I am using latest version of ffmpeg though.

I've tried several installation methods

To Reproduce Steps to reproduce the behavior:

  1. With cams set to 15 FPS for the relevant stream, start a proxy stream with relevant settings - it doesn't matter if using generic rtsp stream or dahua specific commands in unifi-cam-proxy as the result is essentially the same. It also does not matter which rtsp stream you use, if the camera provides more, so long as you adjust FPS on the correct stream.
  2. Observe that the stream works as intended.
  3. In the camera, reduce FPS to e.g. 10 (and check that associated tick options update accordingly). Save.
  4. Observe that the stream now fails repeatedly with av-interleaved-something-something broken pipe.
  5. In the camera, increase FPS back to 15. Save.
  6. Observe that the stream will now resume working as intended after a delay (few minutes).

Expected behavior As there's no documented requirement for FPS, I expect a stream of e.g. 10 FPS or 2 FPS to work equally well as one of 15 FPS. My cams were setup with just 4 FPS to ensure I could store more footage on the previous storage.

Error output Executing this command: unifi-cam-proxy -H 10.0.0.10 -i 10.10.30.11 --mac 12:34:56:AA:FF:11 -c /opt/unifi-cam-proxy/client.pem -t <token> rtsp -s 'rtsp://<user>:<password>@10.10.30.11:554/live' or this command: unifi-cam-proxy -H 10.0.0.10 -i 10.10.30.11 --mac 12:34:56:AA:FF:11 -c /opt/unifi-cam-proxy/client.pem -t <token> dahua -u <user> -p <password> --channel 1 --sub-stream 0 will produce the output below if FPS is set to less than 15 (I have not tested if higher), but will work as expected when FPS=15: unifi | Traceback (most recent call last): unifi | File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main unifi | return _run_code(code, main_globals, None, unifi | File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code unifi | exec(code, run_globals) unifi | File "/app/unifi/clock_sync.py", line 167, in <module> unifi | main() unifi | File "/app/unifi/clock_sync.py", line 153, in main unifi | write(create_script_tag("onClockSync", data, timestamp)) unifi | File "/app/unifi/clock_sync.py", line 87, in write unifi | sys.stdout.buffer.write(data) unifi | BrokenPipeError: [Errno 32] Broken pipe unifi | Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> unifi | BrokenPipeError: [Errno 32] Broken pipe unifi | av_interleaved_write_frame(): Broken pipe unifi | Error writing trailer of pipe:: Broken pipe

Camera (please complete the following information):

Additional context Note that the streams from the cameras, also when using lower FPS, indicate correct metadata in both ffprobe and ffmpeg, so I believe this issue is separate from the much debated adding of metadata issue.

EasternIndustries-IT commented 2 years ago

How do you define fps?

nicoleise commented 2 years ago

How do you define fps?

Same as everyone else, frames per second?

My cameras have a setting for FPS and a separate setting for "ticks" that is automatically updated appropriately when changing FPS.

What I set in the cameras is echoed by ffprobe as well as the verbose output of ffmpeg. Both show the expected resolution and FPS as set up in the cameras.

In other words, if I set 4 FPS (and stuff fails), ffmpeg in verbose mode will state that it is decoding a stream of 4 FPS. If I set 15 FPS (and stuff works), ffmpeg in verbose mode will report an input stream of 15 FPS. Ffprobe will agree.

If has been working reliably since this bug report btw, on 15 FPS. Just limits my storage to ~ 3 days.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

kraney commented 2 years ago

This error means the last command in the pipe has closed - that's netcat, talking over the network to your unifi protect. This happens when unifi doesn't like the connection and closes it on you.