首页 > 解决方案 > 如何将 Opus 流从 Discord 流式传输到 RTP

问题描述

我正在使用 Node.JS Discord 机器人通过 RTP 流式传输语音呼叫。目前,在我的speaking事件处理程序中,我有

var cmd = child_process.spawn("ffmpeg", [
          '-protocol_whitelist', 'file,crypto,sdp,rtp,udp,pipe,opus',
          '-re',
          '-acodec', 'opus',
          '-i', '-',
          '-ar', '8000',
          '-acodec', 'pcm_mulaw',
          '-f', 'mulaw',
          '-f', 'rtp',
          `rtp://${rtp_ip}:${rtp_port}`]);
reciever.createOpusStream(user).pipe(cmd.stdin);

相当于运行ffmpeg命令ffmpeg -protocol_whitelist file,crypto,sdp,rtp,udp,pipe,opus -re acodec opus -i - -ar 8000 -acodec pcm_mulaw -f mulaw -f rtp rtp://${rtp_ip}:${rtp_port}

此命令的变体产生错误,范围从pipe:: Invalid inputpipe:: Invalid argument到任何人Invalid data on input.[mp3 @ 0x5615decebe60] Format mp3 detected only with low score of 1, misdetection possible! [mp3 @ 0x5615decebe60] Failed to read frame size: Could not seek to 16101.可以帮助我将 ReadableStream (opus) 发送到 RTP mulaw 流吗?谢谢!

标签: node.jsffmpegdiscordrtpdiscord.js

解决方案


我在 ffmpeg IRC 上询问并意识到原始 Opus 比特流无法解码。我改为传入原始 PCM 流并添加-f s32le到输入中,该输入在ffmpeg -formats.


推荐阅读