go2rtc icon indicating copy to clipboard operation
go2rtc copied to clipboard

2-way audio with ICSee/dvrip cameras

Open felipecrs opened this issue 3 years ago • 83 comments

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 avatar Sep 11 '23 16:09 felipecrs

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 avatar Sep 11 '23 16:09 felipecrs

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.

felipecrs avatar Sep 11 '23 16:09 felipecrs

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

slydiman avatar Sep 23 '23 14:09 slydiman

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

Djeloan avatar Sep 25 '23 12:09 Djeloan

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 avatar Sep 25 '23 14:09 slydiman

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);
    }

slydiman avatar Sep 30 '23 23:09 slydiman

Supported in latest master:

streams:
  stream: dvrip://username:[email protected]:34567
  tts_only: dvrip://username:[email protected]:34567?backchannel=1
  two_way:
    - dvrip://username:[email protected]:34567
    - dvrip://username:[email protected]:34567?backchannel=1

AlexxIT avatar Oct 11 '23 16:10 AlexxIT

OMG this is amazing. I will test it asap.

felipecrs avatar Oct 11 '23 17:10 felipecrs

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

Djeloan avatar Oct 11 '23 21:10 Djeloan

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

felipecrs avatar Oct 11 '23 21:10 felipecrs

@felipecrs have you tried?

AlexxIT avatar Oct 12 '23 07:10 AlexxIT

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!

slydiman avatar Oct 12 '23 08:10 slydiman

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

felipecrs avatar Oct 12 '23 13:10 felipecrs

@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.

felipecrs avatar Oct 12 '23 13:10 felipecrs

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

AlexxIT avatar Oct 12 '23 14:10 AlexxIT

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 avatar Oct 12 '23 14:10 felipecrs

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

felipecrs avatar Oct 12 '23 14:10 felipecrs

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

AlexxIT avatar Oct 12 '23 14:10 AlexxIT

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

felipecrs avatar Oct 12 '23 14:10 felipecrs

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

AlexxIT avatar Oct 12 '23 15:10 AlexxIT