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
4.21k stars 344 forks source link

Dahua VTO support #49

Open luzik opened 1 year ago

luzik commented 1 year ago

Browser is asking for microphone permission, but no audio from VTO and unmute button is disabled

api:
  base_path: "/go2rtc"
streams:
  vto:
    - rtsp://admin:pass@192.168.124.30/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
[
  {
    "media:0": "video, sendonly, 96 H264/90000",
    "media:1": "audio, sendonly, 97 L16/16000",
    "media:2": "application, sendonly, 107 VND.ONVIF.METADATA/90000",
    "media:3": "audio, recvonly, 97 L16/16000",
    "receive": 824840,
    "remote_addr": "192.168.124.30:554",
    "send": 0,
    "track:0": "96 H264/90000, sinks=1",
    "type": "RTSP client producer",
    "url": "rtsp://192.168.124.30:554/cam/realmonitor?channel=1\u0026subtype=0\u0026unicast=true\u0026proto=Onvif/"
  },
  {
    "remote_addr": "udp4 host 192.168.123.33:63426",
    "send": 826301,
    "type": "WebRTC server consumer",
    "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.4976.0 Safari/537.36"
  }
]
v=0
o=- 8819968399131000794 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE 0 1
a=extmap-allow-mixed
a=msid-semantic: WMS mUTzunk2m8gOBSbMpIqZr9ZW7amqcT2Uu8h0
m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 123 35 36 127 122 125 107 108 109 124 121 120 119 114 37
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:cSCj
a=ice-pwd:azQ5DYFApCx3rzPQWvEqknTA
a=ice-options:trickle
a=fingerprint:sha-256 2A:0A:DC:2B:B9:B5:CC:A3:07:E0:98:E7:B3:65:7A:2B:98:5E:AA:AE:0E:76:DB:71:3F:52:3D:E8:55:2B:F8:F7
a=setup:actpass
a=mid:0
a=extmap:1 urn:ietf:params:rtp-hdrext:toffset
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:3 urn:3gpp:video-orientation
a=extmap:4 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/color-space
a=extmap:9 urn:ietf:params:rtp-hdrext:sdes:mid
a=extmap:10 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id
a=extmap:11 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id
a=recvonly
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:96 VP8/90000
a=rtcp-fb:96 goog-remb
a=rtcp-fb:96 transport-cc
a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack
a=rtcp-fb:96 nack pli
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtpmap:98 VP9/90000
a=rtcp-fb:98 goog-remb
a=rtcp-fb:98 transport-cc
a=rtcp-fb:98 ccm fir
a=rtcp-fb:98 nack
a=rtcp-fb:98 nack pli
a=fmtp:98 profile-id=0
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtpmap:100 VP9/90000
a=rtcp-fb:100 goog-remb
a=rtcp-fb:100 transport-cc
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack
a=rtcp-fb:100 nack pli
a=fmtp:100 profile-id=2
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtpmap:102 VP9/90000
a=rtcp-fb:102 goog-remb
a=rtcp-fb:102 transport-cc
a=rtcp-fb:102 ccm fir
a=rtcp-fb:102 nack
a=rtcp-fb:102 nack pli
a=fmtp:102 profile-id=1
a=rtpmap:123 rtx/90000
a=fmtp:123 apt=102
a=rtpmap:35 AV1/90000
a=rtcp-fb:35 goog-remb
a=rtcp-fb:35 transport-cc
a=rtcp-fb:35 ccm fir
a=rtcp-fb:35 nack
a=rtcp-fb:35 nack pli
a=rtpmap:36 rtx/90000
a=fmtp:36 apt=35
a=rtpmap:127 H264/90000
a=rtcp-fb:127 goog-remb
a=rtcp-fb:127 transport-cc
a=rtcp-fb:127 ccm fir
a=rtcp-fb:127 nack
a=rtcp-fb:127 nack pli
a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f
a=rtpmap:122 rtx/90000
a=fmtp:122 apt=127
a=rtpmap:125 H264/90000
a=rtcp-fb:125 goog-remb
a=rtcp-fb:125 transport-cc
a=rtcp-fb:125 ccm fir
a=rtcp-fb:125 nack
a=rtcp-fb:125 nack pli
a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f
a=rtpmap:107 rtx/90000
a=fmtp:107 apt=125
a=rtpmap:108 H264/90000
a=rtcp-fb:108 goog-remb
a=rtcp-fb:108 transport-cc
a=rtcp-fb:108 ccm fir
a=rtcp-fb:108 nack
a=rtcp-fb:108 nack pli
a=fmtp:108 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=64001f
a=rtpmap:109 rtx/90000
a=fmtp:109 apt=108
a=rtpmap:124 H264/90000
a=rtcp-fb:124 goog-remb
a=rtcp-fb:124 transport-cc
a=rtcp-fb:124 ccm fir
a=rtcp-fb:124 nack
a=rtcp-fb:124 nack pli
a=fmtp:124 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
a=rtpmap:121 rtx/90000
a=fmtp:121 apt=124
a=rtpmap:120 red/90000
a=rtpmap:119 rtx/90000
a=fmtp:119 apt=120
a=rtpmap:114 ulpfec/90000
a=rtpmap:37 flexfec-03/90000
a=rtcp-fb:37 goog-remb
a=rtcp-fb:37 transport-cc
a=fmtp:37 repair-window=10000000
m=audio 9 UDP/TLS/RTP/SAVPF 111 63 103 104 9 0 8 106 105 13 110 112 113 126
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:cSCj
a=ice-pwd:azQ5DYFApCx3rzPQWvEqknTA
a=ice-options:trickle
a=fingerprint:sha-256 2A:0A:DC:2B:B9:B5:CC:A3:07:E0:98:E7:B3:65:7A:2B:98:5E:AA:AE:0E:76:DB:71:3F:52:3D:E8:55:2B:F8:F7
a=setup:actpass
a=mid:1
a=extmap:14 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:9 urn:ietf:params:rtp-hdrext:sdes:mid
a=sendrecv
a=msid:mUTzunk2m8gOBSbMpIqZr9ZW7amqcT2Uu8h0 9654a211-5d7a-4500-8034-3b17b1c6c7a7
a=rtcp-mux
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:63 red/48000/2
a=fmtp:63 111/111
a=rtpmap:103 ISAC/16000
a=rtpmap:104 ISAC/32000
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:106 CN/32000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:112 telephone-event/32000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000
a=ssrc:1443778823 cname:5sgtTCGio9Mf4sP8
a=ssrc:1443778823 msid:mUTzunk2m8gOBSbMpIqZr9ZW7amqcT2Uu8h0 9654a211-5d7a-4500-8034-3b17b1c6c7a7
a=ssrc:1443778823 mslabel:mUTzunk2m8gOBSbMpIqZr9ZW7amqcT2Uu8h0
a=ssrc:1443778823 label:9654a211-5d7a-4500-8034-3b17b1c6c7a7

6webrtc.html:1 Uncaught (in promise) DOMException: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': The remote description was null
calisro commented 1 year ago

The camera is outputting a format that is incompatible with webrtc. Probably AAC. So transcode it to something webrtc friendly or go into your camera settings and change it to a compatible format. If its like my amcrest, you can change it to G.711 so you don't need to transcode.

Alternatively, this would work:

  vto:
    - rtsp://admin:pass@192.168.124.30/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
    - ffmpeg:rtsp://admin:pass@192.168.124.30/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif#audio=opus

https://developer.mozilla.org/en-US/docs/Web/Media/Formats/WebRTC_codecs#supported_audio_codecs

AlexxIT commented 1 year ago

Both send and receive tracks has L16 codec.

L16 is not AAC, but also doesn't supported by WebRTC. It's possible to receive audio with transcoding via FFmpeg.

But send audio (from microphone) with transcoding is not supported yet.

luzik commented 1 year ago

So Dahua VTO2211G do not allow to change audio codec via browser UI. Maybe there is a way using ONVIF, GET param or dahua api ?

Documentation show that device support G.711Mu; G.711u; PCM audio compression https://www.dahuasecurity.com/my/products/All-Products/Video-Intercoms/IP-Series/Villa-Door-Station/Pro-Series/VTO2211G-WP

vlc shows it as PCM S16 BE (s16b) and ffprobe Stream #0:1: Audio: pcm_s16be, 16000 Hz, 1 channels, s16, 256 kb/s

VTO do accept audio via API in ulaw. I believe that VTO supporting g.711 while using SIP protocol

AlexxIT commented 1 year ago

Are you sure you can't change codec via camera Web UI?

image
luzik commented 1 year ago
Zrzut ekranu 2022-09-20 o 19 02 29 Zrzut ekranu 2022-09-20 o 19 02 45
luzik commented 1 year ago

Hmm, interesting ..there is a way to change audio codec using Onvif

https://github.com/blakeblackshear/frigate/discussions/2572

calisro commented 1 year ago

There's likely a way to change it. I can't change it with Amcrest tools but I could change mine with this:

https://dahuawiki.com/ConfigTool

luzik commented 1 year ago

So yeah, it's working. I did used this Happytime onvif client and I hope this settings will stay for ever. If not I will reopen this issue, and ask for help with automating this change.

[ { "media:0": "video, sendonly, 96 H264/90000", "media:1": "audio, sendonly, 0 PCMU/8000", "media:2": "application, sendonly, 107 VND.ONVIF.METADATA/90000", "media:3": "audio, recvonly, 0 PCMU/8000", "receive": 8279516, "remote_addr": "192.168.124.30:554", "send": 993960, "track:0": "0 PCMU/8000, sinks=1", "track:1": "0 PCMU/8000, sinks=1", "type": "RTSP client producer", "url": "rtsp://192.168.124.30:554/cam/realmonitor?channel=1\u0026subtype=0\u0026unicast=true\u0026proto=Onvif/" }, { "receive": 883680, "remote_addr": "udp4 host 192.168.123.33:61346", "send": 8292693, "type": "WebRTC server consumer", "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Safari/605.1.15" } ]

felipecrs commented 1 year ago

@luzik is 2-way audio working for you?

luzik commented 1 year ago

Yeah, latency i low and we are ready to build video doorbell intercom, the only problem is to switch audio codec in programming way. I believe that this could be in scope of this project :)

bonuzzz commented 1 year ago

It is possible to change parameters without onvif client. To get possible audio/video parameters: http://admin:pass@192.168.1.110/cgi-bin/configManager.cgi?action=getConfig&name=Encode For example to change audio bitrate to 8khz: http://admin:pass@192.168.1.110/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Audio.Depth=8

I have VTO2211G. It should work on other models. ps: microphone in chrome doesn't work without https connection

luzik commented 1 year ago

That's a fantastic news for me, because my vto2211g did go to its defaults "L16/16000". Does go2rtc can give support for such behave ? ..I mean if camera returning L16 try such action and try reconnect

felipecrs commented 1 year ago

This approach is a little intrusive, perhaps some kind of automatic codec conversion would be a little better. Refs:

luzik commented 1 year ago

Yeah, You are right, but as conversion make use of CPU, maybe "force_vto_codec=true" is a way to go ?

felipecrs commented 1 year ago

I think the ideal solution would be to:

  1. Report the issue to Dahua, ask them to either make the audio codec selectable from the admin page or prevent it from reverting back to the original codec after some time

But I do understand that it's very unlikely that they would provide any support. Another option would be to look for alternative firmwares, like OpenIPC (which may be already compatible).

That's because, supposedly, this is a camera-specific requirement (other cameras/doorbells allows you to set the codec from their UI).


force_vto_codec=true

If I'm not mistaken, this is an ONVIF configuration (not something specific to VTO), which could potentially mean it would work for other cameras, from other manufactures even. Maybe a better name would be try_adjusting_onvif_audio_codec=true.

felipecrs commented 1 year ago

Since the VTO seems to retain the audio codec configuration for at least some days, a workaround for now is to create a script that fixes the codec and configure it to run automatically every day at midnight in Home Assistant, for example.

bonuzzz commented 1 year ago

to change bitrate from console: curl --digest -u "admin:pass" -g "http://192.168.1.110/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Audio.Depth=8" @felipecrs dahua stops stream when trying to change bitrate, but continue stream if bitrate is the same already. So I think it's better to execute script before start streaming in go2rtc. I tried something like:

 vto:
    - exec:curl --digest -u "admin:pass" -g "http://192.168.1.110/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Audio.Depth=8" 
    - rtsp://admin:pass@192.168.1.110/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
vto:
  - exec:curl --digest -u "admin:pass" -g "http://192.168.1.110/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Audio.Depth=8";ffmpeg -i rtsp://admin:pass@192.168.1.110/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif -vcodec copy -c copy -rtsp_transport tcp -f rtsp {output}
AlexxIT commented 1 year ago

You can use echo source. This is bash script that should print (echo) link to the stream. So you can change codec there.

https://github.com/AlexxIT/go2rtc#source-echo

felipecrs commented 1 year ago

Wow. This is brilliant. The possibilities are endless!

bonuzzz commented 1 year ago

I wrote simple script to check bitrate parameter before start stream. I included sleep to give dahua time to restart rtsp stream.

#!/bin/bash
array=`curl -s --digest -u "admin:pass" -g "http://192.168.1.110/cgi-bin/configManager.cgi?action=getConfig&name=Encode"`
value="table.Encode[0].MainFormat[0].Audio.Depth=16"

if [[ " ${array[@]} " == *"$value"* ]]; then
  curl -s --digest -u "admin:pass" -g "http://192.168.1.110/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Audio.Depth=8"
  sleep 2 
fi
bonuzzz commented 1 year ago

@AlexxIT if I add several strings to source block like

vto:
  - echo: ....
  - ffmpeg: ....

are there executed sequentially or it is bad idea?

felipecrs commented 1 year ago

@bonuzzz you need to convert them all to echo. For example, your first echo should return the rtsp stream string, your second one should return the ffmpeg stream string. (I think)

felipecrs commented 1 year ago

By the way, I don't know if my VTO is different than yours or not, but the setting I need to adjust is:

table.Encode[0].MainFormat[0].Audio.Frequency=16000

Instead of Depth=16

felipecrs commented 1 year ago

This seems to be working well for me. @luzik I suggest you try it too.

  1. Create the file /config/scripts/get_vto_stream.sh
  2. Place the following contents on it, replace the host and password with your values:
#!/bin/bash

creds="admin:pass"
host="192.168.1.40"

# Attempt to change sampling rate. It won't harm if it's already set.
curl --silent --digest --user "${creds}" --globoff \
    "http://${host}/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Audio.Frequency=8000" >&2

echo "rtsp://${creds}@${host}/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif"
  1. Give it execution permission: chmod +x /config/scripts/get_vto_stream.sh
  2. Set your go2rtc.yaml:
streams:
  vto:
    - echo:/config/scripts/get_vto_stream.sh
bonuzzz commented 1 year ago

@felipecrs

By the way, I don't know if my VTO is different than yours or not, but the setting I need to adjust is:

table.Encode[0].MainFormat[0].Audio.Frequency=16000

Instead of Depth=16

Of course frequency. Thanks. I didn't always get mic working in chrome, so tested several options besides frequency. I have vto2211g model. I advice to add sleep command to your script between switching frequency and strart streaming, because dahua is not always finished restart own rtsp stream during 60 sec which go2rtc waits for them. And my script also checking current parameter. ps: 2 sec is just a sample there. may be it need more

felipecrs commented 1 year ago

Yeah, for me it's working fine this way (without the sleep). :)

https://user-images.githubusercontent.com/29582865/193347672-56102a1f-3a7a-43b8-ac9b-bfdf4e6b30c2.mp4

In the video you can see that the codec is wrong (in VLC). Then, opening the stream from go2rtc fixes it quickly. I'm sure it worked because I can hear myself from the microphone (which you can't hear in the video).

By the way I'm using the newest firmware released by Dahua, it's 2022-08-13 V4.600.0000000.0.R.

bonuzzz commented 1 year ago

@felipecrs I have old 2021-07-14 V4.500.0000001.0.R could you send the link for new fw please?

saw your video again. you also didn't restart go2rtc. It's great

felipecrs commented 1 year ago

My model is different than yours...

Mine is:

https://www.dahuasecurity.com/products/All-Products/Video-Intercoms/IP-Series/Villa-Door-Station/Pro-Series/VTO2202F-P-S2

Yours is:

https://www.dahuasecurity.com/products/All-Products/Video-Intercoms/IP-Series/Villa-Door-Station/Pro-Series/VTO2211G-WP

(I think)

But there is a newer fw for you: V4.511.0000000.0.R.220523

Just head to the Downloads -> Firmware in the link above.

bonuzzz commented 1 year ago

Thanks. I updated firmware, but unfortunately nothing is changed and audio/mic is not stable as I see in your video

luzik commented 1 year ago

I am using second stream as frigate source, and frequency change is not enough in my case, so I wrote simple one minute crontab with

curl -s --digest -u "admin:pass" -g "http://IP/cgi-bin/configManager.cgi?action=getConfig&name=Encode" |grep 'table.Encode.0..MainFormat.0..Audio.Compression=G711' || curl -s --digest -u "admin:pass" -g "http://IP/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Audio.Compression=G711&Encode[0].MainFormat[0].Audio.Frequency=8000&Encode[0].ExtraFormat[0].Audio.Compression=AAC"

felipecrs commented 1 year ago

Just for completeness, this is the final version of my script:

#!/bin/bash

set -eu

readonly creds='admin:pass'
readonly host='192.168.1.40'

curl --silent --digest --user "${creds}" --globoff \
    "http://${host}/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Audio.Compression=G711&Encode[0].MainFormat[0].Audio.Frequency=8000" >&2 &

echo "rtsp://${creds}@${host}/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif"
avico78 commented 1 year ago

Hi , Would appreciate your help setting my VTO3211D https://www.dahuasecurity.com/products/productDetail/50437 In config below working - no microphone or sound,

stream:
  intercom_go2rtc: rtsp://admin:mypass@192.168.1.110:554/cam/realmonitor?channel=1&subtype=0  

Same as in ur VTO , can't change the audio settings via the gui , but able to get below infrom via curl:

curl -s --digest -u 'admin:mypass' --globoff "http://192.168.1.110/cgi-bin/configManager.cgi?action=getConfig&name=Encode" |grep '.Audio'

table.Encode[0].ExtraFormat[0].Audio.Bitrate=64
table.Encode[0].ExtraFormat[0].Audio.Compression=PCM
table.Encode[0].ExtraFormat[0].Audio.Depth=16
table.Encode[0].ExtraFormat[0].Audio.Frequency=16000
table.Encode[0].ExtraFormat[0].Audio.Mode=0
table.Encode[0].ExtraFormat[0].Audio.Pack=DHAV
table.Encode[0].ExtraFormat[0].AudioEnable=true
table.Encode[0].ExtraFormat[1].Audio.Bitrate=64
table.Encode[0].ExtraFormat[1].Audio.Compression=PCM
table.Encode[0].ExtraFormat[1].Audio.Depth=16
table.Encode[0].ExtraFormat[1].Audio.Frequency=16000
table.Encode[0].ExtraFormat[1].Audio.Mode=0
table.Encode[0].ExtraFormat[1].Audio.Pack=DHAV
table.Encode[0].ExtraFormat[1].AudioEnable=false
table.Encode[0].ExtraFormat[2].Audio.Bitrate=64
table.Encode[0].ExtraFormat[2].Audio.Compression=PCM
table.Encode[0].ExtraFormat[2].Audio.Depth=16
table.Encode[0].ExtraFormat[2].Audio.Frequency=16000
table.Encode[0].ExtraFormat[2].Audio.Mode=0
table.Encode[0].ExtraFormat[2].Audio.Pack=DHAV
table.Encode[0].ExtraFormat[2].AudioEnable=false
table.Encode[0].MainFormat[0].Audio.Bitrate=64
table.Encode[0].MainFormat[0].Audio.Compression=PCM
table.Encode[0].MainFormat[0].Audio.Depth=16
table.Encode[0].MainFormat[0].Audio.Frequency=16000
table.Encode[0].MainFormat[0].Audio.Mode=0
table.Encode[0].MainFormat[0].Audio.Pack=DHAV
table.Encode[0].MainFormat[0].AudioEnable=true
table.Encode[0].MainFormat[1].Audio.Bitrate=64
table.Encode[0].MainFormat[1].Audio.Compression=PCM
table.Encode[0].MainFormat[1].Audio.Depth=16
table.Encode[0].MainFormat[1].Audio.Frequency=16000
table.Encode[0].MainFormat[1].Audio.Mode=0
table.Encode[0].MainFormat[1].Audio.Pack=DHAV
table.Encode[0].MainFormat[1].AudioEnable=true
table.Encode[0].MainFormat[2].Audio.Bitrate=64
table.Encode[0].MainFormat[2].Audio.Compression=PCM
table.Encode[0].MainFormat[2].Audio.Depth=16
table.Encode[0].MainFormat[2].Audio.Frequency=16000
table.Encode[0].MainFormat[2].Audio.Mode=0
table.Encode[0].MainFormat[2].Audio.Pack=DHAV
table.Encode[0].MainFormat[2].AudioEnable=true
table.Encode[0].SnapFormat[0].Audio.Bitrate=64
table.Encode[0].SnapFormat[0].Audio.Compression=G.711A
table.Encode[0].SnapFormat[0].Audio.Depth=16
table.Encode[0].SnapFormat[0].Audio.Frequency=8000
table.Encode[0].SnapFormat[0].Audio.Mode=0
table.Encode[0].SnapFormat[0].Audio.Pack=DHAV
table.Encode[0].SnapFormat[0].AudioEnable=false
table.Encode[0].SnapFormat[1].Audio.Bitrate=64
table.Encode[0].SnapFormat[1].Audio.Compression=G.711A
table.Encode[0].SnapFormat[1].Audio.Depth=16
table.Encode[0].SnapFormat[1].Audio.Frequency=8000
table.Encode[0].SnapFormat[1].Audio.Mode=0
table.Encode[0].SnapFormat[1].Audio.Pack=DHAV
table.Encode[0].SnapFormat[1].AudioEnable=false
table.Encode[0].SnapFormat[2].Audio.Bitrate=64
table.Encode[0].SnapFormat[2].Audio.Compression=G.711A
table.Encode[0].SnapFormat[2].Audio.Depth=16
table.Encode[0].SnapFormat[2].Audio.Frequency=8000
table.Encode[0].SnapFormat[2].Audio.Mode=0
table.Encode[0].SnapFormat[2].Audio.Pack=DHAV
table.Encode[0].SnapFormat[2].AudioEnable=false

Update: After setting the audio to G711:

 curl -s --digest -u 'admin:pass' --globoff "http://192.168.1.110/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Audio.Compression=G711&Encode[0].MainFormat[0].Audio.Frequency=8000"

I do get the sound in the url: http://192.168.1.113:1984/webrtc.html?src=intercom_go2rtc

But it is not working in HA : Using generic camera integration i added the link :

rtsp://192.168.1.113:8554/intercom_go2rtc

for all other cameras it does working

AlexxIT commented 1 year ago

By default HA shows streams in HLS format. It support same codecs as MSE, but also works on iPhones: https://github.com/AlexxIT/go2rtc#codecs-madness

avico78 commented 1 year ago

By default HA shows streams in HLS format. It support same codecs as MSE, but also works on iPhones: https://github.com/AlexxIT/go2rtc#codecs-madness

Thanks @AlexxIT and thanks for your work !

so yes , on mobile i do get the sound but not via chrome . is it possible to enable the micophone on mobile?

Basically till I got to go2rc i use the webrtc on HA and its working amazingly (before it - i just give up using camers on HA). But i can't tell or see the big advantage of moving to go2rtc in the context of use in home assistant . Will the latency suppose to improve? I'm not sure but based on this post Microphone supposed to work ?

AlexxIT commented 1 year ago

Different users have different needs. Some people are satisfied with frequent snapshot updates. By the way HomeKit cameras in HA do exactly that.

felipecrs commented 1 year ago

I think what you need is:

So that you can have microphone working when using MSE.

felipecrs commented 1 year ago

Is mse.html supposed to support 2-way audio? For me it's only working on webrtc.html and I wonder if it's a limitation of the player itself or codec/format issues.

NickM-27 commented 1 year ago

Is mse.html supposed to support 2-way audio? For me it's only working on webrtc.html and I wonder if it's a limitation of the player itself or codec/format issues.

Based on AlexxIt's response in the other issue I don't think it does natively. Seems WebRTC does but MSE would need an alternate solution to support two way audio:

Without WebRTC, you have to find other ways to encode and transmit. Also in both directions. In case of MSE, it is Media Source Extensions + WebSocket for receiving data.

In any case, mse.html does not currently get the microphone like webrtc.html does so seems to be entirely expected currently

epicurean70 commented 1 year ago

wow, this is way over my head. I have a VTO2211G-WP. Please advise what do I have to do to get video and audio feed to my frigate.

felipecrs commented 1 year ago

Ok, I have some unfortunate news.

When using this trick to have 2-way audio working in go2rtc with VTO, the SIP calling with the Asterisk add-on stops working properly. No audio can be heard from the doorbell in a call.

The error in Asterisk logs are:

[Dec 21 12:06:06] DEBUG[599][C-00000004]: chan_pjsip.c:897 chan_pjsip_read_stream: Oooh, got a frame with format of alaw on channel 'PJSIP/8001-00000004' when it has not been negotiated

And no one seems to know how to fix it from Asterisk side.

This may be another reason for:

morpheus8888 commented 1 year ago

3. chmod +x /config/scripts/get_vto_stream.sh

Just for completeness, this is the final version of my script:

#!/bin/bash

set -eu

readonly creds='admin:pass'
readonly host='192.168.1.40'

curl --silent --digest --user "${creds}" --globoff \
    "http://${host}/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Audio.Compression=G711&Encode[0].MainFormat[0].Audio.Frequency=8000" >&2 &

echo "rtsp://${creds}@${host}/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif"

i'm getting this error

image image image image

@felipecrs thx

felipecrs commented 1 year ago

Are you running go2rtc via docker? You should mount the script into the container.

morpheus8888 commented 1 year ago

Are you running go2rtc via docker? You should mount the script into the container.

I m running it as addon on homeassistant

felipecrs commented 1 year ago

Try to call this script from the Terminal add-on, it should work too. That should help you debug it before passing in to go2rtc.

morpheus8888 commented 1 year ago

Try to call this script from the Terminal add-on, it should work too. That should help you debug it before passing in to go2rtc.

image same error, i dont know why

edit: i used this command and now it works thx sed -i -e 's/\r$//' nomefile.sh

felipecrs commented 1 year ago

makes sense. line endings issue.

Heronimonimo commented 1 year ago

@felipecrs @morpheus8888 I've been trying to set this up on my Dahua WP2111D-WP. Interestingly enough I can send sound to the camera with Tinycam but can't hear the camera mic. In go2rtc it is exactly the other way around. I can hear the camera mic but I can't get output from the speaker in the camera.

Below the info on the stream. Can you see something I'm missing here?

{
  "producers": [
    {
      "type": "RTSP active producer",
      "url": "rtsp://192.168.2.33:554/cam/realmonitor?channel=1\u0026subtype=0/",
      "remote_addr": "192.168.2.33:554",
      "user_agent": "go2rtc/1.4.0",
      "medias": [
        "video, recvonly, H.264 High 3.1",
        "audio, recvonly, L16/16000"
      ],
      "receivers": [
        "96 H264, bytes=32351736, senders=1",
        "97 L16/16000, bytes=2689920, senders=1"
      ],
      "recv": 35397456
    },
    {
      "url": "echo:/config/scripts/get_vto_stream.sh"
    }
  ],
  "consumers": [
    {
      "type": "WebRTC/WebSocket async passive consumer",
      "remote_addr": "udp4 host 192.168.2.19:56785",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.48",
      "medias": [
        "video, sendonly, VP8, RTX, VP9, H264, AV1, RED, ULPFEC, FLEXFEC-03",
        "audio, sendonly, OPUS/48000/2, RED/48000/2, G722/8000, PCMU/8000, PCMA/8000, CN/8000, TELEPHONE-EVENT/48000, TELEPHONE-EVENT/8000"
      ],
      "senders": [
        "102 H264, bytes=32351736, receivers=1",
        "8 PCMA/8000, bytes=2689920, receivers=1"
      ],
      "send": 33441026
    }
  ]
}
AlexxIT commented 1 year ago

@Heronimonimo There is no back audio in your info. Check if the camera has any other RTSP connections with the microphone turned on. Because only one can be active simultaneously

Heronimonimo commented 1 year ago

@AlexxIT This is with an active stream with microphone turned on. Any idea what Tinycam does to get it working out of the box?

{
  "producers": [
    {
      "type": "RTSP active producer",
      "url": "rtsp://192.168.2.33:554/cam/realmonitor?channel=1\u0026subtype=0/",
      "remote_addr": "192.168.2.33:554",
      "user_agent": "go2rtc/1.4.0",
      "medias": [
        "video, recvonly, H.264 High 3.1",
        "audio, recvonly, L16/16000"
      ],
      "receivers": [
        "96 H264, bytes=14440515, senders=1",
        "97 L16/16000, bytes=841600, senders=1"
      ],
      "recv": 15426451
    },
    {
      "url": "echo:/config/scripts/get_vto_stream.sh"
    }
  ],
  "consumers": [
    {
      "type": "WebRTC/WebSocket async passive consumer",
      "remote_addr": "udp4 host 192.168.2.19:63200",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.48",
      "medias": [
        "video, sendonly, VP8, RTX, VP9, H264, AV1, RED, ULPFEC, FLEXFEC-03",
        "audio, recvonly, OPUS/48000/2, RED/48000/2, G722/8000, PCMU/8000, PCMA/8000, CN/8000, TELEPHONE-EVENT/48000, TELEPHONE-EVENT/8000",
        "audio, sendonly, OPUS/48000/2, RED/48000/2, G722/8000, PCMU/8000, PCMA/8000, CN/8000, TELEPHONE-EVENT/48000, TELEPHONE-EVENT/8000"
      ],
      "receivers": [
        "111 OPUS/48000/2, bytes=186635, senders=0"
      ],
      "senders": [
        "102 H264, bytes=14440515, receivers=1",
        "8 PCMA/8000, bytes=841600, receivers=1"
      ],
      "recv": 241075,
      "send": 14826563
    }
  ]
}
Heronimonimo commented 1 year ago

This is the output using your rtsplog tool. It seems to show a sendonly track.


2023/05/01 09:11:27 RTSP/1.0 200 OK
CSeq: 2
Public: OPTIONS, DESCRIBE, ANNOUNCE, SETUP, PLAY, RECORD, PAUSE, TEARDOWN, SET_PARAMETER, GET_PARAMETER
Server: Rtsp Server/3.0

2023/05/01 09:11:27 RTSP/1.0 200 OK
CSeq: 3
Cache-Control: must-revalidate
Content-Base: rtsp://192.168.2.33:554//
Content-Length: 573
Content-Type: application/sdp
X-Accept-Dynamic-Rate: 1

v=0
o=- 2251938251 2251938251 IN IP4 0.0.0.0
s=Media Server
c=IN IP4 0.0.0.0
t=0 0
a=control:*
a=packetization-supported:DH
a=rtppayload-supported:DH
a=range:npt=now-
m=video 0 RTP/AVP 96
a=control:trackID=0
a=framerate:30.000000
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z2QAH6y0AoAt0qQAAAMABAAAAwDxgQAA+f8AAEZP+974XhEI1AA=,aM48MAA=
a=recvonly
m=audio 0 RTP/AVP 97
a=control:trackID=1
a=rtpmap:97 L16/16000
a=recvonly
m=audio 0 RTP/AVP 97
a=control:trackID=5
a=rtpmap:97 L16/16000
a=sendonly
2023/05/01 09:11:27 available tracks: [0xc00010a660 0xc00010a6c0 0xc00010a720]