gpt4 book ai didi

docker - 流式传输多个 docker 容器音频

转载 作者:行者123 更新时间:2023-12-04 23:19:53 26 4
gpt4 key购买 nike

我想在一台机器上运行多个 docker 容器并通过 RTP 流式传输音频。我可以使用以下命令运行有声音的应用程序:

sudo docker run -it \
--device /dev/snd \
-e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native \
-v ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native \
-v ~/.config/pulse/cookie:/root/.config/pulse/cookie \
--group-add $(getent group audio | cut -d: -f3) \

ubuntu:16.04 /bin/bash
它工作正常,当我在它播放的容器中播放任何声音时,我可以听到它,我可以用 FFmpeg 流式传输它。问题是当我运行多个容器并从任何容器播放任何声音时,似乎它们在 pulseaudio 服务器中使用相同的接收器,所以我无法将它们分开,每个流客户端都会听到来自所有正在运行的容器的所有声音。我怎样才能实现我的目标?
我的 FFmpeg 流代码:
ffmpeg -f alsa -i pulse -acodec libmp3lame -ab 128k -ac 2 -ar 48000 -c:a libopus -f rtp rtp://$IP:4001

最佳答案

未经测试,但看起来好像您正在使用 alsa而不是 pulse ,并且还使用两个编解码器( -acodec-a:c 是相同的)
你能试一下吗:

ffmpeg -f pulse -i default -ab 128k -ac 2 -c:a libopus -f rtp rtp://$IP:400
此外,如果您尝试在 docker 容器中运行脉冲音频,您可能需要启动 pulseaudio守护进程:
# your docker apt-get:
apt-get install -y pulseaudio

# your entrypoint/command script:
pulseaudio &

# or, if using root (dont)
pulseaudio --system &

关于docker - 流式传输多个 docker 容器音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68838102/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com