Open luzik opened 2 years 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
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.
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
Are you sure you can't change codec via camera Web UI?
Hmm, interesting ..there is a way to change audio codec using Onvif
There's likely a way to change it. I can't change it with Amcrest tools but I could change mine with this:
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" } ]
@luzik is 2-way audio working for you?
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 :)
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
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
This approach is a little intrusive, perhaps some kind of automatic codec conversion would be a little better. Refs:
Yeah, You are right, but as conversion make use of CPU, maybe "force_vto_codec=true" is a way to go ?
I think the ideal solution would be to:
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
.
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.
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}
You can use echo source. This is bash script that should print (echo) link to the stream. So you can change codec there.
Wow. This is brilliant. The possibilities are endless!
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
@AlexxIT if I add several strings to source block like
vto:
- echo: ....
- ffmpeg: ....
are there executed sequentially or it is bad idea?
@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)
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
This seems to be working well for me. @luzik I suggest you try it too.
/config/scripts/get_vto_stream.sh
#!/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"
chmod +x /config/scripts/get_vto_stream.sh
go2rtc.yaml
:streams:
vto:
- echo:/config/scripts/get_vto_stream.sh
@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
Yeah, for me it's working fine this way (without the sleep). :)
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.
@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
My model is different than yours...
Mine is:
Yours is:
(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.
Thanks. I updated firmware, but unfortunately nothing is changed and audio/mic is not stable as I see in your video
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"
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"
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
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
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 ?
Different users have different needs. Some people are satisfied with frequent snapshot updates. By the way HomeKit cameras in HA do exactly that.
I think what you need is:
So that you can have microphone working when using MSE.
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.
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
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.
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:
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
@felipecrs thx
Are you running go2rtc via docker? You should mount the script into the container.
Are you running go2rtc via docker? You should mount the script into the container.
I m running it as addon on homeassistant
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.
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.
same error, i dont know why
edit: i used this command and now it works thx sed -i -e 's/\r$//' nomefile.sh
makes sense. line endings issue.
@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
}
]
}
@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
@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
}
]
}
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]
Browser is asking for microphone permission, but no audio from VTO and unmute button is disabled