keshavdv / unifi-cam-proxy

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

Broken Pipe #312

Closed adminy closed 9 months ago

adminy commented 1 year ago

Camera

RTSP

Firmware version of the camera

N/A

Description

My Configuration

services:
  # RTSP server for all the cameras
  cams_server:
    image: aler9/rtsp-simple-server
    environment:
      - RTSP_PROTOCOLS=tcp
      - MTX_PROTOCOLS=tcp
    network_mode: host
    privileged: true
  # RTSP camera is the producer here
  cam1producer:
    depends_on:
      - cams_server
    image: lscr.io/linuxserver/ffmpeg:latest
    network_mode: host
    privileged: true
    volumes:
      - /run/udev:/run/udev:ro
    command: >-
      -channel_layout mono -r 15
      -re -i ${CAM1_URL} -hide_banner -loglevel warning -y
      -c:v libx264 -an -f rtsp -rtsp_transport tcp
      "rtsp://${PI_HOST}:${RTSP_PORT}/${CAM1_PATH}"
  # Proxy to unifi protect app
  cam1:
    depends_on:
      - cam1producer
    restart: unless-stopped
    image: keshavdv/unifi-cam-proxy:dev
    network_mode: host
    privileged: true
    volumes:
      - "./client.pem:/client.pem"
    command: >-
      unifi-cam-proxy --host "${UNIFI_HOST}" --mac "${CAM1_MAC}"
        --ip "${CAM1_IP}"
        --cert /client.pem --token "${CAM1_TOKEN}"
        rtsp -s "rtsp://${PI_HOST}:${RTSP_PORT}/${CAM1_PATH}"
        --ffmpeg-args "-an -c:v copy"

Traceback Error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/app/unifi/clock_sync.py", line 179, in <module>
    main(parse_args())
  File "/app/unifi/clock_sync.py", line 156, in main
    write(read_bytes(source, payload_size))
  File "/app/unifi/clock_sync.py", line 28, in write
    sys.stdout.buffer.write(data)
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
2023-06-05 16:48:10 MD RTSPCam[1] INFO Processing [ChangeVideoSettings] message
av_interleaved_write_frame(): Broken pipe
Error writing trailer of pipe:: Broken pipe
Error closing file pipe:: Broken pipe

How to reproduce

Run the above configuration and you get the traceback.

Expected behaviour

No errors.

Screenshots

No response

Aditional information

I also tried a different rtsp stream directly: Still got:

2023-06-06 06:48:28 home RTSPCam[1] WARNING Previous ffmpeg process for video3 died.
2023-06-06 06:48:28 home RTSPCam[1] INFO Spawning ffmpeg for video3 (QpmOivryit1NH6mk): ffmpeg -nostdin -loglevel error -y -avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1 -timeout 15000000 -rtsp_transport tcp -i "rtsp://192.168.1.100:554/user=md&password=md&channel=1&stream=0.sdp?real_stream--rtp-caching=100" -c:v copy -ar 32000 -ac 1 -codec:a aac -b:a 32k -metadata streamName=QpmOivryit1NH6mk -f flv - | /usr/local/bin/python -m unifi.clock_sync --write-timestamps | nc 100.70.138.129 7550
Traceback (most recent call last):
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
    exec(code, run_globals)
  File "/app/unifi/clock_sync.py", line 179, in <module>
  File "/app/unifi/clock_sync.py", line 179, in <module>
    main(parse_args())
    main(parse_args())
  File "/app/unifi/clock_sync.py", line 156, in main
  File "/app/unifi/clock_sync.py", line 156, in main
    write(read_bytes(source, payload_size))
    write(read_bytes(source, payload_size))
  File "/app/unifi/clock_sync.py", line 28, in write
  File "/app/unifi/clock_sync.py", line 28, in write
    sys.stdout.buffer.write(data)
    sys.stdout.buffer.write(data)
BrokenPipeError: [Errno 32] Broken pipe
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
BrokenPipeError: [Errno 32] Broken pipe
av_interleaved_write_frame(): Broken pipe
av_interleaved_write_frame(): Broken pipe
    Last message repeated 2 times
Error writing trailer of pipe:: Broken pipe
Error closing file pipe:: Broken pipe
    Last message repeated 1 times
Error writing trailer of pipe:: Broken pipe
Error closing file pipe:: Broken pipe
cakysk commented 1 year ago

Hi there, I am getting as well broken pipe errors, I tried several rtsp test streams, however all with the same result. Is there an approach that works with the latest Protect versions? thanks all for hints.

msa0311 commented 1 year ago

Would be interesting for me to know as well!

kloknibor commented 1 year ago

did you guys try the dev container? this works somewhat

cakysk commented 1 year ago

yep... I'm running all my tests with DEV container.. is there an online RSTP stream that works and can be used for testing?

msa0311 commented 1 year ago

yes, the dev container works fine for me! Thanks!

Would be great if you could make this work with latest protect version somehow. Its so sad that this isnt a native feature from unifi protect.

Is there a way to donate for this project?

plopp commented 1 year ago

I just want to chime in and say that the dev docker image (keshavdv/unifi-cam-proxy:dev) works like a charm. :tada:

I followed the documentation for everything else: https://unifi-cam-proxy.com/

cakysk commented 1 year ago

I can confirm that it is working also for me.. in the end the issue was that I had (on camera) h264 profile set to 'High Profile', once I set it to 'Main Profile', all started to work. Only issue I have right now, is time.. that is out of sync.

jmorris644 commented 1 year ago

The dev is not working for me. I have reolink cams. Using docker-compose and specifying reolink I get the error that ' reolink' is not a valid option. Somewhere a space is being added.

When I try the options for reolink with the --fmpeg options I either get the broken pip error or a bad cseq error.

msa0311 commented 12 months ago

When using the dev image my protect app on my dream machine is randomly restarting every couple of minutes.

stale[bot] commented 11 months 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.

willh20 commented 10 months ago

I experienced the same issue and running the dev image resolved the broken pipe error.

simryc commented 10 months ago

today i installed clean debian 12 and installed docker with unifi-proxy. I got a broken pipe error. Details attached I am using UnifiProtect 2.8.35 and Dahua Cameras. Using VLC rstp stream is working unifiproxy.txt Can u help me :)?

simryc commented 10 months ago

I can confirm that it is working also for me.. in the end the issue was that I had (on camera) h264 profile set to 'High Profile', once I set it to 'Main Profile', all started to work. Only issue I have right now, is time.. that is out of sync.

Actually after changing to dev the image is displayed but there is a problem with time synchronization, it is impossible to play the recorded video - playback does not work and the time on the preview jumps very strangely

stale[bot] commented 9 months 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.