Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2-way audio with ICSee/dvrip cameras #633

Closed
felipecrs opened this issue Sep 11, 2023 · 55 comments
Closed

2-way audio with ICSee/dvrip cameras #633

felipecrs opened this issue Sep 11, 2023 · 55 comments
Labels
enhancement New feature or request
Milestone

Comments

@felipecrs
Copy link
Contributor

Many cheap chinese cameras are using this ICSee. I bought this one: https://aliexpress.com/item/1005005731238053.html

It's relatively good, although it does not have the capability of changing the stream codec from H265 to H264.

But I have another ICSee based camera as well.

The app is good as well. A lot better than Tuya.

It looks like these cameras uses the DVRIP protocol. My RTSP URLs looks like:

rtsp://192.168.1.21:554/user=tema_password=<password>_channel=0_stream=0&onvif=0.sdp

It would be awesome if 2-way audio could work with it.

@felipecrs felipecrs changed the title 2-way audio with ICSee app 2-way audio with ICSee cameras Sep 11, 2023
@felipecrs
Copy link
Contributor Author

felipecrs commented Sep 11, 2023

2-way audio works through its web UI:

image

Although it requires the installation of a "VideoPlayTool" to properly open it.

@AlexxIT if someday you are interested in implementing this I can give you direct access to the camera.

@felipecrs
Copy link
Contributor Author

felipecrs commented Sep 11, 2023

Oh, and by the way DVRIP source also works with this camera:

streams:
  icsee_camera:
    - dvrip://tema:<password>@192.168.1.21:34567?channel=0&subtype=1

Meaning that maybe the support for 2-way audio could be general for any DVRIP-based camera.

@AlexxIT AlexxIT added the enhancement New feature or request label Sep 11, 2023
@slydiman
Copy link

Agreed. It would be great to support 2-way audio for DVRIP/XM/Sofia-based cameras.

@felipecrs felipecrs changed the title 2-way audio with ICSee cameras 2-way audio with ICSee/DVRip cameras Sep 23, 2023
@felipecrs felipecrs changed the title 2-way audio with ICSee/DVRip cameras 2-way audio with ICSee/dvrip cameras Sep 23, 2023
@Djeloan
Copy link

Djeloan commented Sep 25, 2023

Oh yes! I was trying to do it but couldn't ... i can talk trough that xmeye application tho.

@slydiman
Copy link

Oh yes!

@Djeloan, Please vote on the initial message at the top of this page. The author must see that it is important enhancement.

@slydiman
Copy link

slydiman commented Sep 30, 2023

Here is the Talk command implementation for DVRIP protocol
https://github.com/667bdrm/sofiactl/blob/master/sofiactl.pl#L2286
The source file must be PCM G711 ALAW 8kHz mono.

    $decoded = $dvr->PrepareGenericCommand(IPcam::TALK_CLAIM, { # 1434
        Name => 'OPTalk',
        OPTalk => {
            Action => "Claim",
            AudioFormat => {
                BitRate => 128,
                EncodeType => "G711_ALAW",
                SampleBit => 8,
                SampleRate => 8000
            }
        }
    });

    $decoded = $dvr->PrepareGenericCommand(IPcam::TALK_REQ, { # 1430
        Name => 'OPTalk',
        OPTalk => {
            Action => "Start",
            AudioFormat => {
                BitRate => 128,
                EncodeType => "G711_ALAW",
                SampleBit => 8,
                SampleRate => 8000
            }
        }
    });

    if ($cfgInputFile ne '') {
        my $size = -s $cfgInputFile;
        print "File size: $size\n";
        my $count = 0;
        open(IN, "< $cfgInputFile");
        while ($count < $size) {
            my $data;
            read(IN, $data, 320);
            #print $data . "\n";
            $count += 320;
            my $audio_pkt = $dvr->BuildRawPacket(IPcam::TALK_CU_PU_DATA, # 1432
                pack('CCCCCCS', (0x00, 0x00, 0x01, 0xFA, 0x0E, 0x02, 320)) . $data);  # 320 bytes 40ms audio to camera
            $dvr->{socket}->send($audio_pkt);

            my $reply_head = $dvr->GetReplyHead();  # 1433
            $dvr->GetReplyData($reply_head);  # 8+160 bytes data - 20ms mic audio from camera
        }
        close(IN);
    }

@AlexxIT
Copy link
Owner

AlexxIT commented Oct 11, 2023

Supported in latest master:

streams:
  stream: dvrip://username:password@192.168.1.123:34567
  tts_only: dvrip://username:password@192.168.1.123:34567?backchannel=1
  two_way:
    - dvrip://username:password@192.168.1.123:34567
    - dvrip://username:password@192.168.1.123:34567?backchannel=1

@felipecrs
Copy link
Contributor Author

OMG this is amazing. I will test it asap.

@Djeloan
Copy link

Djeloan commented Oct 11, 2023

Supported in latest master:

Means that will be available in some next update or the current one (1.7.1) ?
Tested it now, but couldn't get it to work, so im guessing it's in the next update

@felipecrs
Copy link
Contributor Author

https://github.com/AlexxIT/go2rtc?tab=readme-ov-file#go2rtc-dev-version

@AlexxIT
Copy link
Owner

AlexxIT commented Oct 12, 2023

@felipecrs have you tried?

@slydiman
Copy link

Great work! Thank you very much!
But it works with the microphone only from go2rtc addon UI: Links, select video+audio+microphone = two way audio from camera, click webrtc.html local WebRTC viewer.
I was shocked - there is no way to turn on the microphone in the HA UI. The solution with browser_mod does not work for me (in case of few HA users and Android app).
The next step is to ubdate WebRTC camera custom card to enable the microphone.
Install the Frigate/Frigate addon + Frigate integration + Frigate custom card for 1 button microphone is overkill!

@felipecrs
Copy link
Contributor Author

Frigate Card is now supporting external go2rtc in latest dev. Meaning you don't need Frigate.

@felipecrs
Copy link
Contributor Author

@felipecrs have you tried?

I'm sorry not yet. But I will try it very soon. My ICSee camera is currently far away from my current location.

@AlexxIT
Copy link
Owner

AlexxIT commented Oct 12, 2023

@felipecrs you can send audio to it an check result via stream (if you have remote access)

@felipecrs
Copy link
Contributor Author

Oh, yes. This is what I see:

{
  "producers": [
    {
      "type": "RTSP passive producer",
      "url": "rtsp://127.0.0.1:8554/8aa14331e4a4907604463ca9c8ca54eb",
      "remote_addr": "127.0.0.1:38036",
      "user_agent": "ffmpeg/go2rtc",
      "sdp": "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=go2rtc/1.7.1\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=tool:libavformat LIBAVFORMAT_VERSION\r\nm=video 0 RTP/AVP 96\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QMKawsqAoBbpp4AAADAAgAAAMAxHhAIVA=,aO44sA==; profile-level-id=640C29\r\na=control:streamid=0\r\n",
      "medias": ["video, recvonly, H.264 High 4.1"],
      "receivers": ["96 H264, bytes=5876964, senders=1"],
      "recv": 5928476
    },
    {
      "type": "RTSP active producer",
      "url": "rtsp://127.0.0.1:8554/rua_h265?audio=all",
      "remote_addr": "127.0.0.1:8554",
      "user_agent": "go2rtc/1.7.1",
      "sdp": "v=0\r\no=- 1 1 IN IP4 0.0.0.0\r\ns=go2rtc/1.7.1\r\nc=IN IP4 0.0.0.0\r\nt=0 0\r\nm=audio 0 RTP/AVP 96\r\na=rtpmap:96 PCMA/8000\r\na=control:trackID=0\r\nm=audio 0 RTP/AVP 97\r\na=rtpmap:97 MPEG4-GENERIC/8000\r\na=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=158856E500\r\na=control:trackID=1\r\n",
      "medias": [
        "audio, recvonly, PCMA/8000",
        "audio, recvonly, MPEG4-GENERIC/8000"
      ],
      "receivers": ["96 PCMA/8000, bytes=297920, senders=1"],
      "recv": 453571
    }
  ],
  "consumers": [
    {
      "type": "WebRTC/WebSocket async passive consumer",
      "remote_addr": "udp4 srflx 179.106.189.52:64259 related 192.168.1.15:64259",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
      "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, L16, PCML",
        "audio, recvonly, 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=16351, senders=0"],
      "senders": [
        "102 H264, bytes=1290962, receivers=1",
        "8 PCMA/8000, bytes=65920, receivers=1"
      ],
      "recv": 23261,
      "send": 1371330
    }
  ]
}

@felipecrs
Copy link
Contributor Author

Oh sorry, wait a sec. I think I made a mistake.

@AlexxIT
Copy link
Owner

AlexxIT commented Oct 12, 2023

I don't need logs. Just check via live stream if you can hear some audio file. You can send it via WebUI links.html page

@felipecrs
Copy link
Contributor Author

Yes I can hear myself!!! That's amazing! It's working nice, thanks a lot!

@AlexxIT
Copy link
Owner

AlexxIT commented Oct 12, 2023

Nice. Thanks to @slydiman for perl and sharing access to camera.

@AlexxIT AlexxIT added this to the v1.7.2 milestone Oct 12, 2023
@felipecrs
Copy link
Contributor Author

felipecrs commented Oct 12, 2023

go2rtc.zip (latest artifact for amd64)

If someone wants to quickly try this out with Frigate:

ha addons stop ccab4aaf_frigate
wget https://github.com/AlexxIT/go2rtc/files/12884449/go2rtc.zip -O /config/go2rtc
chmod +x /config/go2rtc
ha addons start ccab4aaf_frigate

@slydiman
Copy link

slydiman commented Oct 12, 2023

Frigate Card is now supporting external go2rtc in latest dev. Meaning you don't need Frigate.

I tried it yesterday - no luck. @felipecrs, can you provide a link to the documentation or config example?

@felipecrs
Copy link
Contributor Author

felipecrs commented Oct 12, 2023

@slydiman, before anything else you need to have go2rtc exposed as https with a valid certificate. I do that using the NGINX Proxy Manager add-on.

But go2rtc itself also supports https/tls, although it will be harder to configure.

Do you have this part done?

@slydiman
Copy link

Sure. HA with https and go2rts master work just fine.

I tried to update AlexxIT's WebRTC camera custom card today. I have successfully enabled the microphone recording in the browser but stuck with creating the correct rtc offer request.

@felipecrs
Copy link
Contributor Author

felipecrs commented Oct 12, 2023

Sorry, I have no config samples to provide. As I mentioned, I use NGINX Proxy Manager to expose go2rtc through HTTPS. Also, I don't use the Frigate card without the Frigate integration.

Frigate documentation says that 2 way audio requires a frigate camera provided by the Frigate integration.

I think you missed my point that this feature was only added to the development branch of the Frigate card.

Maybe you can find more help in dermotduffy/frigate-hass-card#1206.

@slydiman
Copy link

slydiman commented Oct 13, 2023

I have configured NGINX to access go2rtc addon through HTTPS.
Finally I was able to get 2-way audio working with the latest dev frigate-card and the following config

        - type: custom:frigate-card
          cameras:
          - live_provider: go2rtc
            go2rtc:
              url: https://mydomain:1985
              stream: cam_with_audio
              modes:
               - webrtc
          menu:
            buttons:
              microphone:
                enabled: true

But go2rtc does not have any authorization and it will be a security hole. I can't use it outside my home network.
The bottom line is that we still need to update WebRTC Camera card to support microphone with go2rtc through hassio ingress.

@felipecrs
Copy link
Contributor Author

felipecrs commented Oct 13, 2023

But go2rtc does not have any authorization and it will be a security hole. I can't use it outside my home network.

Yes, that is far from ideal. But you can set go2rtc to require user and password, and maybe you can embed the user and password in the go2rtc.url in the frigate card like https://user:password@mydomain.com:1935.

I agree it would be great if WebRTC Camera had built-in support for 2-way audio. But @AlexxIT is aware, he just didn't have the time and to ship it yet.

Similarly, support for go2rtc without its direct exposure is something @dermotduffy is also aware and he would like to ship it. Likewise, he probably didn't have time to work on it yet.

Needless to say that both has no obligation to work on anything and probably contributions are welcome.

Few months ago we did not have any kind of 2-way audio support at all in Home Assistant. Things are evolving, and will continue to evolve and be more seamless as the time goes. :)

@slydiman
Copy link

slydiman commented Oct 13, 2023

I have updated WebRTC Camera to enable the microphone for 2-way audio.

AlexxIT/WebRTC#579

It works just fine in a browser with go2rtc addon. HA must be HTTPS.

Unfortunately the mic does not work inside the Android HA app - it shows that the mic is used, but there is no any transmission.

@AlexxIT
Copy link
Owner

AlexxIT commented Oct 14, 2023

https://github.com/AlexxIT/go2rtc/releases/tag/v1.8.0

@Cr4z33
Copy link

Cr4z33 commented Oct 15, 2023

Sorry if my question might sound silly, but is there any chance this can work also with a Amcrest AD410 video doorbell or does it have no DVRIP support?

@slydiman
Copy link

Amcrest AD410 video doorbell

Seems it uses VoIP/SIP protocols for audio conversations. It is not DVRIP compatible at all.

@Cr4z33
Copy link

Cr4z33 commented Oct 15, 2023

@slydiman that's what I was fearing... OK thanks.

@AlexxIT
Copy link
Owner

AlexxIT commented Oct 15, 2023

Amcrest AD410 doorbell support RTSP with two way audio

@felipecrs
Copy link
Contributor Author

felipecrs commented Oct 15, 2023

Guys, since we are talking about two-way audio here, I have two feature requests in Frigate Card that may interest you too:

If you find them useful, please vote on them with a thumbs up. But please do not vote if you don't find them useful.

@felipecrs
Copy link
Contributor Author

felipecrs pushed a commit to felipecrs/go2rtc that referenced this issue Oct 20, 2023
@PaulBiod
Copy link

PaulBiod commented Oct 21, 2023

Hi,
I'm also using a chinese icsee cam which supports 2 ways audio, but I can't get it to work (updated to last webrtc.), I have no microphone on the stream.

My card looks like this :

image

any help would be appreciated

@felipecrs
Copy link
Contributor Author

How does the go2rtc config looks like?

Also is your HA exposed as HTTPS?

@PaulBiod
Copy link

I use webrtc to show cards of my onvif cams (setup in ICSee)
image

Yes, my HA is exposed as https via duckdns

@felipecrs
Copy link
Contributor Author

You need to add a go2rtc configuration with the drip: back channel link.

@PaulBiod
Copy link

PaulBiod commented Oct 21, 2023

sorry for beeing noob, but how can I achieve this ? I only installed webrtc to have greater cam cards, and go2rtc is included in web2rtc hacs integration

@felipecrs
Copy link
Contributor Author

I use the go2rtc add-on, but I think you can probably create one file named go2rtc.yaml at config with something like:

streams:
  camera.jardin_profile_000: 
    - "{input}"
    - dvrip://username:password@192.168.1.123:34567?backchannel=1

But I am not sure if the "{input}" line will work as I intended. @AlexxIT can comment more on this.

@slydiman
Copy link

go2rtc add-on config must look like

streams:
  camera.jardin_profile_000: 
   - dvrip://admin:password@192.168.1.123:34567?channel=0&subtype=1
   - dvrip://admin:password@192.168.1.123:34567?backchannel=1

My card looks like this :

Here is the correct sample of webrtc-camera card AlexxIT/WebRTC#579 (comment)
Forget about mic: true. It was my suggestion in the pool request. The final implementation requires media: video,audio,microphone.
In your case

type: 'custom:webrtc-camera'
ui: true
streams:
- url: camera.jardin_profile_000
  mode: webrtc
  name: '🎙️ Mic on'
  media: video,audio,microphone
muted: false
...

@PaulBiod
Copy link

Hi all,
thanks for your time, so, If I understood, I just have to create a file named go2rtc.yaml in the same path where my HAOS config file is, with just these lines (with my IPs of course and credentials):

streams:
camera.jardin_profile_000:

  • dvrip://admin:password@192.168.1.123:34567?channel=0&subtype=1
  • dvrip://admin:password@192.168.1.123:34567?backchannel=1

And then use this code for the card :

type: 'custom:webrtc-camera'
ui: true
streams:

  • url: camera.jardin_profile_000
    mode: webrtc
    name: '🎙️ Mic on'
    media: video,audio,microphone
    muted: false
    ...

Thanks guys

@slydiman
Copy link

slydiman commented Oct 21, 2023

If I understood, I just have to create a file named go2rtc.yaml in the same path where my HAOS config file is

Right. Be sure the addon go2rtc is started. You can open go2rtc addon settings and click Open web UI or enable the option Show in sidebar, then click on go2rtc in left sidebar. You will see go2rtc's web UI. Then you can click on Config tab, edit the config and then click the button Save & Restart.

Note the yaml rules. The padding for streams: and muted: false must be the same. It is important.

streams:
 - url: camera.jardin_profile_000
   mode: webrtc
   name: '🎙️ Mic on'
   media: video,audio,microphone
muted: false

... at the end means etc. Don't copy ... as is ;)

@PaulBiod
Copy link

Ok guys,
so, I created the file :
Capture

Then, restarted HAOS, went to my dashboard, and create a card :

Capture3

The result is the same (no micro) :
Capture2

Here is my onvifer result showing the ports :

Capture d’écran 2023-10-21 141622

Any idea ?
Thanks

@slydiman
Copy link

No need to restart HAOS. It is enough to restart only go2rtc addon after changing go2rtc.yaml

If you need to see the name of the stream with the mic icon and be able to switch off the mic just add a second stream with the same camera, other name and media: video,audio

Be sure you have set permissions to the browser to use the microphone. You must see the rec icon on the page tab. If you are using Google Chrome
Video with muted audio:
Screenshot 2023-10-21 180216
Video and audio:
Screenshot 2023-10-21 180225
Video, audio and microphone:
Screenshot 2023-10-21 180237
Click on the mic icon in the address bar, allow the mic access and select the audio input (microphone) device:
Screenshot 2023-10-21 180611

@PaulBiod
Copy link

Thanks, indeed the micro in the adress bar was disabled, I enabled it, refresh the page, put a second stream, now I can switch between the streams, but the stream with micro ON doesn't send any audio from my PC...
image

image

@PaulBiod
Copy link

PaulBiod commented Oct 21, 2023

So, I tried with my tablet, it asked me for audio permissions, then I can hear myself speaking, but very low, I only realised it because of the larsen (being close to the camera). The cam speaker is at 100% volume, when I try with icsee, it's clear and loud.
With my laptop, no sound at all. Tried with chrome and edge, asked me for micro permission, refreshed, still no sound...

@eerison
Copy link

eerison commented Jan 5, 2024

I didn't test it yet, But I want to say thank you guys for all effort in this feature ❤️

@eerison
Copy link

eerison commented Jan 5, 2024

Hey @dbuezas
I guess you was trying to make this work, don't you?

@felipecrs
Copy link
Contributor Author

It's working just fine for me since the day it was implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants