Skip to content

Fix audio sample rate for some xiaomi cameras #2006

@Eyeless77

Description

@Eyeless77

I have the following config:

streams:
    mi360:
        - xiaomi://<id>:cn@<ip>?did=<did>&model=chuangmi.camera.029a02&subtype=auto
        - ffmpeg:mi360#video=h264
        - ffmpeg:mi360#audio=opus

I tried to use different sources from my go2rtc instance via VLC and Frigate (RTSP, MP4 and others) and in every stream the audio seems to be pitched down a lot. Are there any errors in my config or is it a known issue? Native Xiaomi app plays original sound with no pitch.

Transcoding for h264&opus is made for HomeKit.

ffprobe:

{
  "producers": [
    {
      "id": 383,
      "format_name": "xiaomi",
      "protocol": "cs2+udp",
      "remote_addr": "<ip>:27239",
      "source": "xiaomi://<id>:cn@<ip>?client_private=<private>client_public=<public>device_public=<public>did=<did>model=chuangmi.camera.029a02\u0026sign=<sign>subtype=auto\u0026vendor=cs2",
      "medias": [
        "video, recvonly, H265",
        "audio, recvonly, PCMA/8000",
        "audio, sendonly, PCMA/8000"
      ],
      "receivers": [
        {
          "id": 384,
          "codec": {
            "codec_name": "hevc",
            "codec_type": "video"
          },
          "childs": [
            156,
            387,
            389
          ],
          "bytes": 2405382,
          "packets": 438
        },
        {
          "id": 385,
          "codec": {
            "codec_name": "pcm_alaw",
            "codec_type": "audio",
            "sample_rate": 8000
          },
          "childs": [
            158,
            394,
            397
          ],
          "bytes": 350080,
          "packets": 547
        }
      ],
      "senders": [
        {
          "id": 400,
          "codec": {
            "codec_name": "ANY",
            "codec_type": ""
          },
          "parent": 399
        }
      ]
    },
    {
      "id": 390,
      "format_name": "rtsp",
      "protocol": "rtsp+tcp",
      "remote_addr": "127.0.0.1:33528 forwarded 127.0.0.1:8554",
      "source": "exec:ffmpeg -hide_banner -v error -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://127.0.0.1:8554/mi360?video\u0026source=ffmpeg:mi360%23video%3Dh264 -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency -pix_fmt:v yuv420p -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/300ec3c6e7c5b3226f1b5a9399f3a5e8",
      "url": "rtsp://127.0.0.1:8554/mi360?video\u0026source=ffmpeg:mi360%23video%3Dh264",
      "sdp": "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=go2rtc/1.9.13\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=tool:libavformat 61.7.100\r\nm=video 0 RTP/AVP 96\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QAKay0BQF/ywgAAAMACAAAAwFEeMGV,aO8Pyw==; profile-level-id=640029\r\na=control:streamid=0\r\n",
      "user_agent": "ffmpeg/go2rtc",
      "medias": [
        "video, recvonly, H264"
      ],
      "receivers": [
        {
          "id": 391,
          "codec": {
            "codec_name": "h264",
            "codec_type": "video",
            "level": 41,
            "profile": "High"
          },
          "childs": [
            392
          ],
          "bytes": 125704,
          "packets": 113
        }
      ],
      "bytes_recv": 127088
    },
    {
      "id": 395,
      "format_name": "rtsp",
      "protocol": "rtsp+tcp",
      "remote_addr": "127.0.0.1:33542 forwarded 127.0.0.1:8554",
      "source": "exec:ffmpeg -hide_banner -v error -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://127.0.0.1:8554/mi360?audio\u0026source=ffmpeg:mi360%23audio%3Dopus -c:a libopus -application:a lowdelay -min_comp 0 -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/d18183ccb8783e34eb8b9e2ca6c6ca42",
      "url": "rtsp://127.0.0.1:8554/mi360?audio\u0026source=ffmpeg:mi360%23audio%3Dopus",
      "sdp": "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=go2rtc/1.9.13\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=tool:libavformat 61.7.100\r\nm=audio 0 RTP/AVP 96\r\nb=AS:64\r\na=rtpmap:96 opus/48000/2\r\na=control:streamid=0\r\n",
      "user_agent": "ffmpeg/go2rtc",
      "medias": [
        "audio, recvonly, OPUS/48000/2"
      ],
      "receivers": [
        {
          "id": 396,
          "codec": {
            "channels": 2,
            "codec_name": "opus",
            "codec_type": "audio",
            "sample_rate": 48000
          },
          "childs": [
            398
          ]
        }
      ]
    }
  ],
  "consumers": [•••]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions