go2rtc icon indicating copy to clipboard operation
go2rtc copied to clipboard

The audio captured from the ALSA source is distorted and crackling.

Open LOVE2CMOL opened this issue 1 month ago • 5 comments

ffmpeg:
  h264/rkmpp: "-codec:v h264_rkmpp -g 50 -bf 0 -preset:v medium -tune:v zerolatency -profile:v high -level:v 5.1"
  h265/rkmpp: "-codec:v hevc_rkmpp -g 50 -bf 0 -preset:v medium -tune:v zerolatency -profile:v main -level:v 5.1" 
streams:
  ugreen_4k_30_265:
    - ffmpeg:device?video=/dev/video0&framerate=30&input_format=mjpeg&video_size=3840x2160#video=h265/rkmpp
    - alsa:device?audio=/dev/snd/pcmC2D0c
{
    "sources": [
        {
            "name": "rockchip,hdmi0 i2s-hifi-0",
            "info": "Formats: s16le 6 s32le 18, Rates: 32000-48000, Channels: 2-2",
            "url": "alsa:device?audio=/dev/snd/pcmC0D0p"
        },
        {
            "name": "USB Audio",
            "info": "Formats: s16le, Rates: 48000-48000, Channels: 2-2",
            "url": "alsa:device?audio=/dev/snd/pcmC1D0c"
        },
        {
            "name": "USB Audio",
            "info": "Formats: s16le, Rates: 48000-48000, Channels: 2-2",
            "url": "alsa:device?audio=/dev/snd/pcmC2D0c"
        }
    ]
}
{
  "producers": [
    {
      "id": 11,
      "format_name": "rtsp",
      "protocol": "rtsp+tcp",
      "remote_addr": "127.0.0.1:58066",
      "source": "exec:ffmpeg -hide_banner -v info -f v4l2 -framerate 30 -input_format mjpeg -video_size 3840x2160 -i /dev/video0 -codec:v hevc_rkmpp -g 50 -bf 0 -preset:v medium -tune:v zerolatency -profile:v main -level:v 5.1 -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/b259b2460c96d9f360b4e34e7fa29b72",
      "sdp": "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=No Name\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=tool:libavformat 60.16.100\r\nm=video 0 RTP/AVP 96\r\nb=AS:2000\r\na=rtpmap:96 H265/90000\r\na=fmtp:96 sprop-vps=QAEMAf//IWAAAAMAgAAAAwAAAwCZvAk=; sprop-sps=QgEBIWAAAAMAgAAAAwAAAwCZoAHgIAIcWNvuTKYBAAADAAEAAAMAHgg=; sprop-pps=RAHA88BNkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\r\na=control:streamid=0\r\n",
      "user_agent": "ffmpeg/go2rtc",
      "medias": [
        "video, recvonly, H265"
      ],
      "receivers": [
        {
          "id": 12,
          "codec": {
            "codec_name": "hevc",
            "codec_type": "video"
          },
          "childs": [
            13
          ],
          "bytes": 29913751,
          "packets": 22518
        }
      ],
      "bytes_recv": 30184639
    },
    {
      "id": 14,
      "format_name": "alsa",
      "medias": [
        "audio, recvonly, PCML/16000"
      ],
      "receivers": [
        {
          "id": 15,
          "codec": {
            "codec_name": "pcm_s16le",
            "codec_type": "audio",
            "sample_rate": 16000
          },
          "childs": [
            16
          ],
          "bytes": 3799680,
          "packets": 5937
        }
      ],
      "bytes_recv": 22798080
    }
  ],
  "consumers": [
    {
      "id": 10,
      "format_name": "webrtc",
      "protocol": "ws+udp",
      "remote_addr": "192.168.83.111:63228 prflx",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
      "medias": [
        "video, sendonly, VP8, VP9, H264, AV1, H265",
        "audio, sendonly, OPUS/48000/2, G722/8000, PCMU/8000, PCMA/8000, L16"
      ],
      "senders": [
        {
          "id": 13,
          "codec": {
            "codec_name": "hevc",
            "codec_type": "video"
          },
          "parent": 12,
          "bytes": 29913751,
          "packets": 22518
        },
        {
          "id": 16,
          "codec": {
            "codec_name": "pcm_alaw",
            "codec_type": "audio",
            "sample_rate": 8000
          },
          "parent": 15,
          "bytes": 3799680,
          "packets": 5937
        }
      ],
      "bytes_send": 31223463
    }
  ]
}

LOVE2CMOL avatar Dec 17 '25 07:12 LOVE2CMOL

ffmpeg:
  h264/rkmpp: "-codec:v h264_rkmpp -g 50 -bf 0 -preset:v medium -tune:v zerolatency -profile:v high -level:v 5.1"
  h265/rkmpp: "-codec:v hevc_rkmpp -g 50 -bf 0 -preset:v medium -tune:v zerolatency -profile:v main -level:v 5.1" 
streams:
  ugreen_4k_30_265:
    - ffmpeg:device?video=/dev/video0&framerate=30&input_format=mjpeg&video_size=3840x2160#video=h265/rkmpp
    - alsa:device?audio=/dev/snd/pcmC2D0c
{
    "sources": [
        {
            "name": "rockchip,hdmi0 i2s-hifi-0",
            "info": "Formats: s16le 6 s32le 18, Rates: 32000-48000, Channels: 2-2",
            "url": "alsa:device?audio=/dev/snd/pcmC0D0p"
        },
        {
            "name": "USB Audio",
            "info": "Formats: s16le, Rates: 48000-48000, Channels: 2-2",
            "url": "alsa:device?audio=/dev/snd/pcmC1D0c"
        },
        {
            "name": "USB Audio",
            "info": "Formats: s16le, Rates: 48000-48000, Channels: 2-2",
            "url": "alsa:device?audio=/dev/snd/pcmC2D0c"
        }
    ]
}
{
  "producers": [
    {
      "id": 11,
      "format_name": "rtsp",
      "protocol": "rtsp+tcp",
      "remote_addr": "127.0.0.1:58066",
      "source": "exec:ffmpeg -hide_banner -v info -f v4l2 -framerate 30 -input_format mjpeg -video_size 3840x2160 -i /dev/video0 -codec:v hevc_rkmpp -g 50 -bf 0 -preset:v medium -tune:v zerolatency -profile:v main -level:v 5.1 -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/b259b2460c96d9f360b4e34e7fa29b72",
      "sdp": "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=No Name\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=tool:libavformat 60.16.100\r\nm=video 0 RTP/AVP 96\r\nb=AS:2000\r\na=rtpmap:96 H265/90000\r\na=fmtp:96 sprop-vps=QAEMAf//IWAAAAMAgAAAAwAAAwCZvAk=; sprop-sps=QgEBIWAAAAMAgAAAAwAAAwCZoAHgIAIcWNvuTKYBAAADAAEAAAMAHgg=; sprop-pps=RAHA88BNkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\r\na=control:streamid=0\r\n",
      "user_agent": "ffmpeg/go2rtc",
      "medias": [
        "video, recvonly, H265"
      ],
      "receivers": [
        {
          "id": 12,
          "codec": {
            "codec_name": "hevc",
            "codec_type": "video"
          },
          "childs": [
            13
          ],
          "bytes": 29913751,
          "packets": 22518
        }
      ],
      "bytes_recv": 30184639
    },
    {
      "id": 14,
      "format_name": "alsa",
      "medias": [
        "audio, recvonly, PCML/16000"
      ],
      "receivers": [
        {
          "id": 15,
          "codec": {
            "codec_name": "pcm_s16le",
            "codec_type": "audio",
            "sample_rate": 16000
          },
          "childs": [
            16
          ],
          "bytes": 3799680,
          "packets": 5937
        }
      ],
      "bytes_recv": 22798080
    }
  ],
  "consumers": [
    {
      "id": 10,
      "format_name": "webrtc",
      "protocol": "ws+udp",
      "remote_addr": "192.168.83.111:63228 prflx",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
      "medias": [
        "video, sendonly, VP8, VP9, H264, AV1, H265",
        "audio, sendonly, OPUS/48000/2, G722/8000, PCMU/8000, PCMA/8000, L16"
      ],
      "senders": [
        {
          "id": 13,
          "codec": {
            "codec_name": "hevc",
            "codec_type": "video"
          },
          "parent": 12,
          "bytes": 29913751,
          "packets": 22518
        },
        {
          "id": 16,
          "codec": {
            "codec_name": "pcm_alaw",
            "codec_type": "audio",
            "sample_rate": 8000
          },
          "parent": 15,
          "bytes": 3799680,
          "packets": 5937
        }
      ],
      "bytes_send": 31223463
    }
  ]
}

docker-compoeser [f6df5dbe8d61]

services:
  go2rtc:
    container_name: go2rtc
    image: alexxit/go2rtc:latest-rockchip
    network_mode: bridge
    privileged: true         
    restart: unless-stopped  
    volumes:
      - "/home/love2cmol/go2rtc:/config"  
    devices:
      - "/dev/video*:/dev/video*"
      - "/dev/snd:/dev/snd"
      - "/dev/dri:/dev/dri" 
    ports:
      - '1984:1984'
      - '8554:8554'
      - '8555:8555'
      - '8555:8555/udp'

LOVE2CMOL avatar Dec 17 '25 07:12 LOVE2CMOL

Please use ffmpeg source until this issue is fixed.

AlexxIT avatar Dec 17 '25 08:12 AlexxIT

I'm using the Docker version, and the ffmpeg source doesn't have the ALSA flag enabled. Additionally, because I'm using rkmpp, the binary version cannot recognize the system-installed ffmpeg and reports an "unknown version" error.I might try compiling a separate ffmpeg build.

LOVE2CMOL avatar Dec 17 '25 08:12 LOVE2CMOL

I'm using the Docker version, and the ffmpeg source doesn't have the ALSA flag enabled. Additionally, because I'm using rkmpp, the binary version cannot recognize the system-installed ffmpeg and reports an "unknown version" error.I might try compiling a separate ffmpeg build.

I've temporarily resolved this issue and can offer a workaround for others facing the same problem. Steps:

Create an empty stream configuration within go2rtc. Externally, use ffmpeg with ALSA to push the audio stream to go2rtc.

 ffmpeg -f alsa -i hw:1,0 -ar 48000 -ac 2  -acodec aac -b:a 320k -profile:a aac_low   -f rtsp rtsp://url/audio_stream1

Finally, have go2rtc internally mux this configured audio stream into the video stream.

  audio_stream1:
  test:
    - ffmpeg:device?video=/dev/video2&framerate=30&input_format=nv12&video_size=1920x1080#video=h264/rkmpp
    - ffmpeg:audio_stream1#audio=opus

LOVE2CMOL avatar Dec 17 '25 10:12 LOVE2CMOL

I think the built-in transcoding isn't working properly. But to figure it out, I need to replicate the situation myself. And that takes time.

AlexxIT avatar Dec 17 '25 11:12 AlexxIT