koush / scrypted

Scrypted is a high performance video integration and automation platform
https://scrypted.app
Other
4.19k stars 248 forks source link

Unifi Protect 2 way audio fails #510

Closed sundar2012 closed 1 year ago

sundar2012 commented 1 year ago

Hi, Scrypted is working great to connect my homekit cameras but 2 way audio is not working for me within homekit. I’m on the latest Unifi OS (UNVR) and Protect general release versions. Scrypted is running as a native windows service (using the Choco installation procedure). Heres the log:

[HomeKit]: Received first two way audio packet, starting intercom.
starting 2 way audio [
  '-hide_banner',
  '-fflags',
  'nobuffer',
  '-flags',
  'low_delay',
  '-protocol_whitelist',
  'pipe,udp,rtp,file,crypto,tcp',
  '-acodec',
  'libopus',
  '-ac',
  '1',
  '-f',
  'sdp',
  '-i',
  'tcp://127.0.0.1:62212',
  '-acodec',
  'aac',
  '-profile:a',
  'aac_low',
  '-threads',
  '0',
  '-avioflags',
  'direct',
  '-fflags',
  '+flush_packets',
  '-flush_packets',
  '1',
  '-flags',
  '+global_header',
  '-ar',
  '22050',
  '-ac',
  '1',
  '-b:a',
  '16k',
  '-f',
  'adts',
  'pipe:3'
]
sending audio data to wss://192.168.1.213:7443/ws/talkback?uniqid=ws-99a69988-0811-4e15-8961-03394f6cd80b
Input #0, sdp, from 'tcp://127.0.0.1:62212':
  Metadata:
    title           : HomeKit Audio Talkback
  Duration: N/A, bitrate: N/A

  Stream #0:0: Audio: opus, 48000 Hz, stereo, s16

Stream mapping:
  Stream #0:0 -> #0:0
 (opus (libopus) -> aac (native))
Press [q] to stop, [?] for help

tcp://127.0.0.1:62212: Unknown error

Output #0, adts, to 'pipe:3':

  Metadata:
    title           : HomeKit Audio Talkback
    encoder         : Lavf59.16.100
  Stream #0:0: Audio: aac (LC), 22050 Hz, mono, fltp, 16 kb/s
    Metadata:
      encoder         : Lavc59.18.100 aac

size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    

video/audio detected, discarding further input
ffmpeg exited
[HomeKit]: handleStreamRequest { sessionID: 'd51b883b-ec2a-438e-8b3b-f35eb0fd6ce2', type: 'stop' }
[HomeKit]: streaming session killed, duration: 34s
[HomeKit]: rtp sink closed
[HomeKit]: Stopping intercom.
[Rebroadcast Plugin]: High active rebroadcast clients: 0
sundar2012 commented 1 year ago

2 way doesn’t work within homekit, but it does work in the scrypted ui. Here’s the console output when it works via the scrypted ui:

starting 2 way audio [
  '-hide_banner',           '-fflags',
  'nobuffer',               '-flags',
  'low_delay',              '-rtsp_transport',
  'udp',                    '-i',
  'rtsp://127.0.0.1:62458', '-acodec',
  'aac',                    '-profile:a',
  'aac_low',                '-threads',
  '0',                      '-avioflags',
  'direct',                 '-fflags',
  '+flush_packets',         '-flush_packets',
  '1',                      '-flags',
  '+global_header',         '-ar',
  '22050',                  '-ac',
  '1',                      '-b:a',
  '16k',                    '-f',
  'adts',                   'pipe:3'
]
sending audio data to wss://192.168.1.213:7443/ws/talkback?uniqid=ws-7c1105ca-8ba8-4396-9498-cb563c1461de
Input #0, rtsp, from 'rtsp://127.0.0.1:62458':
  Duration: N/A, start: 0.000000, bitrate: N/A

  Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp

Stream mapping:
  Stream #0:0 -> #0:0 (opus (native) -> aac (native))
Press [q] to stop, [?] for help

Output #0, adts, to 'pipe:3':

  Metadata:

    encoder         : Lavf59.16.100
  Stream #0:0: Audio: aac (LC), 22050 Hz, mono, fltp, 16 kb/s
    Metadata:
      encoder         : Lavc59.18.100 aac
size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
video/audio detected, discarding further input
ffmpeg exited
[WebRTC Plugin]: signalingState closed
[WebRTC Plugin]: sig change closed
[WebRTC Plugin]: connectionState closed
[WebRTC Plugin]: iceConnectionState closed
[Rebroadcast Plugin]: High active rebroadcast clients: 0
sundar2012 commented 1 year ago

I removed the hardcoded server IP and restarted scrypted. Now it works…not sure what that means. Feel free to close but might warrant investigation?

koush commented 1 year ago

I don't think that server address has anything to do with it. I'd try adding it again to confirm it breaks.

sundar2012 commented 1 year ago

Confirmed that is what breaks it. Note that I’m setting the server address as my private lan (192.168.x.xx) address.

koush commented 1 year ago

probably a routing/address/config issue on your end. working fine here with g4 doorbell as well as others.

the scrypted server address should work, and that should be the address that is visible to the other devices on your lan.