AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
6.69k stars 481 forks source link

Dahua and Tapo cameras: two-way not working for Frigate and HA #1464

Open derekcentrico opened 15 hours ago

derekcentrico commented 15 hours ago

I have Tapo and Dahua cameras. I set them up with Frigate based upon their documentation. However, two-way communication doesn't work at all. Dahua shows the mic icon but doesn't transmit. Tapo doesn't even show the mic icon. I am using HTTPS. They referred me here and I've been tinkering ever since.

  • Block domains n-device-api.tplinkcloud.com and security.iot.i.tplinknbu.com

@mofman thank you for the info. Blocked and configured with tapo://.. TAPO C120 now works with 2-way audio in Home Assistant.

@mofman and @rici44 would you be kind enough to provide Frigate go2rtc and camera configs, and maybe any card configuration data from HA?

Anyone else with thoughts I'd be grateful.

This is what I got going currently:

Frigate

go2rtc:
  streams:
    garage:  # Dahua camera
      - rtsp://admin:pass@192.168.1.240:554/cam/realmonitor?channel=1&subtype=0#backchannel=0
      - rtsp://admin:pass@192.168.1.240:554/cam/realmonitor?channel=1&subtype=0
    garage_sub: # Dahua camera
      - rtsp://admin:pass@192.168.1.240:554/cam/realmonitor?channel=1&subtype=2#backchannel=0
      - rtsp://admin:pass@192.168.1.240:554/cam/realmonitor?channel=1&subtype=2

    kitchen: # Tapo C120
      - ffmpeg:rtsp://tapocam:pass@192.168.1.246:554/stream1#audio=aac#video=copy
      - tapo://passhash@192.168.1.246
    kitchen_sub: # Tapo C120
      - ffmpeg:rtsp://tapocam:pass@192.168.1.246:554/stream2#audio=aac#video=copy
      - tapo://passhash@192.168.1.246

cameras:
  garage:
  ....
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-aac
      inputs:
        - path: 
            rtsp://admin:pass@192.168.1.240:554/cam/realmonitor?channel=1&subtype=0
          input_args: preset-rtsp-restream
          roles:
            - record
        - path: 
            rtsp://admin:pass@192.168.1.240:554/cam/realmonitor?channel=1&subtype=2
          input_args: preset-rtsp-restream
          roles:
            - detect
            - audio
      hwaccel_args: preset-vaapi
  ....
  kitchen:
  ....
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-copy
      inputs:
        - path: rtsp://tapocam:pass@192.168.1.246:554/stream2
          roles:
            - detect
          input_args: preset-rtsp-restream-low-latency
        - path: rtsp://127.0.0.1:8554/kitchen
          input_args: preset-rtsp-restream
          roles:
            - record
            - audio
#      hwaccel_args: preset-vaapi
    live:
      stream_name: kitchen
  ....

Home Assistant Card:

type: grid
cards:
  - type: custom:frigate-card
    cameras:
      - camera_entity: camera.kitchen_2
        go2rtc:
          modes: []
        webrtc_card: {}
        live_provider: go2rtc
    view:
      update_force: true
      update_seconds: 0
    menu:
      buttons:
        mute:
          enabled: true
        play:
          enabled: true
        microphone:
          enabled: true
          type: momentary
          alignment: matching
      style: overlay
    live:
      preload: true
      controls:
        thumbnails:
          media: clips
      auto_play: all
      auto_mute: all
      microphone:
        always_connected: true
    media_viewer:
      auto_mute: never
      controls:
        next_previous: {}
    image:
      mode: camera
type: custom:frigate-card
cameras:
  - camera_entity: camera.garage
    live_provider: auto
    go2rtc:
      modes:
        - webrtc
    image:
      refresh_seconds: 2
view:
  default: image
  camera_select: live
  update_seconds: 2
image:
  mode: camera
  refresh_seconds: 2
performance:
  profile: low
dimensions:
  aspect_ratio_mode: dynamic
mofman commented 15 hours ago

Showing you the part of the config which need to get right,

you need admin: and your tapo account password sha256 hashed in upper case (the password you use to login to tapo services)

your ffmpeg line is wrong too

go2rtc:
  streams:
    Kitchen:
      - tapo://admin:XXXB3B88C3CA41847092362896109AC1EA681A2E82ED40BFD25C8E25EEFDFXXX@192.168.0.240
      - ffmpeg:Kitchen#audio=aac#audio=opus
derekcentrico commented 15 hours ago

Showing you the part of the config which need to get right,

you need admin: and your tapo account password sha256 hashed in upper case

your ffmpeg line is wrong too

go2rtc:
  streams:
    Kitchen:
      - tapo://admin:XXXB3B88C3CA41847092362896109AC1EA681A2E82ED40BFD25C8E25EEFDFXXX@192.168.0.240
      - ffmpeg:Kitchen#audio=aac#audio=opus

Thanks, I'll tweak that. How do you have the URL for the actual cameras?

mofman commented 15 hours ago

You mean the ip address?

rici44 commented 15 hours ago

@derekcentrico For this setup I use only go2rtc and Custom: WebRTC Camera card in HA

go2rtc config

cam4: 
  - tapo://admin:AAAAA......................BBBBB@192.168.200.133

Custom: WebRTC Camera

type: custom:webrtc-camera
streams:
  - url: cam4
    mode: webrtc
    media: video,audio,microphone
derekcentrico commented 15 hours ago

You mean the ip address?

@mofman Like the camera section in Frigate config.

cameras:  
kitchen:
  ....
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-copy
      inputs:
        - path: rtsp://tapocam:pass@192.168.1.246:554/stream2
          roles:
            - detect
          input_args: preset-rtsp-restream-low-latency
        - path: rtsp://127.0.0.1:8554/kitchen
          input_args: preset-rtsp-restream
mofman commented 15 hours ago
go2rtc:
  streams:
    Kitchen:
      - tapo://admin:XXXB3B88C3CA41847092362896109AC1EA681A2E82ED40BFD25C8E25EEFDFXXX@192.168.0.240
      - ffmpeg:Kitchen#audio=aac#audio=opus

cameras:
  Kitchen:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/Kitchen
          roles:
            - detect
      output_args:
        record: preset-record-generic-audio-aac
    detect:
      enabled: true
    objects:
      track:
        - person
        - cat
        - dog
    motion:
      mask: 0,0.046,0.359,0.047,0.358,0,0,0.002

Assuming its running on the location and the dafault port, use rtsp://127.0.0.1:8554/Kitchen - keep the name the same.

derekcentrico commented 7 hours ago

@mofman and @rici44 thank you both.

I revised my cameras. Oddly, I get this error when using the go2rtc URL for the camera:

rtsp://127.0.0.1:8554/kitchen: Invalid data found when processing input

Cloud password is the password that goes to the Tapo app, correct? I tried that one and the tapocam:password from the RTSP setup just for kicks. No go.

2024-11-15 17:56:35.141980187  [2024-11-15 17:56:35] frigate.video                  ERROR   : portable: Unable to read frames from ffmpeg process.
2024-11-15 17:56:35.142058459  [2024-11-15 17:56:35] frigate.video                  ERROR   : portable: ffmpeg process is not running. exiting capture thread...
2024-11-15 17:56:35.157629698  17:56:35.157 WRN [rtsp] error="streams: 401 Unauthorized, exec: rtsp://127.0.0.1:8554/kitchen?audio: Invalid data found when processsing input\n" stream=kitchen
2024-11-15 17:56:35.243087508  [2024-11-15 17:56:35] audio.kitchen                  ERROR   : ffmpeg process is not running, restarting...

I have firmware 1.1.3 flashed to it, using the very last release of 1.1.3 available as a bin.

Did y'all have an issue with a password or anything?

derekcentrico commented 7 hours ago

LOL now I get "2024-11-15 18:31:15.077453990 18:31:15.077 WRN [rtsp] error="streams: Expected StatusCode to be 401, received 200, exec: rtsp://127.0.0.1:8554/kitchen?video&audio: Invalid data found when processing input\n" stream=portable" using "Tapo_C120v1_en_1.1.3_Build_230930_Rel.56236n_up_boot-signed_1697192563556.bin" instead of "Tapo_C120v1_en_1.1.3_Build_230930_Rel.56236n_up_boot-signed_1697194362284.bin"

mofman commented 7 hours ago

Did you block the domains I suggested?

derekcentrico commented 6 hours ago

Did you block the domains I suggested?

Yeah I blocked them via pihole.

My firewalla shows only one domain it's hitting, 5 times. aps1-relay-dcipc-beta.i.tplinknbu.com

mofman commented 6 hours ago

Are you familiar with python?

If so

Can you try this code, install pytapo via pip then create the script below replacing with your values and let me know what your response is when you run it

pip3 install pytapo

from pytapo import Tapo

user = "admin" # leave this variable as 'admin'
password = "XXXXXXXXX" # password for your **tapo account** in plain text (not hashed)
host = "192.168.0.1" # ip of the camera, example: 192.168.1.52

tapo = Tapo(host, user, password)

print(tapo.getBasicInfo())