使用Node.js将音频流式传输到html5音频标签并绕过iOS限制

时间:2022-03-29 19:00:42

I'm currently working on a project that use HTML5 audio and we have problems with the limitations on iOS devices (mostly multiple audio channels limitation).

我目前正在开发一个使用HTML5音频的项目,我们遇到iOS设备限制问题(主要是多个音频通道限制)。

I was thinking that it may be possible to control the sounds server-side using node.js. The client would connect to a single audio url and the node server will stream live sounds trough this single channel doing all the mixing and transitions live on the server.

我当时认为可以使用node.js控制服务器端的声音。客户端将连接到单个音频URL,节点服务器将通过此单个通道流式传输实时声音,在服务器上进行所有混音和转换。

Is it technically possible? Can you parse audio on node.js and do some live mixing? Do you think the server will explode with more than 5 simultaneous clients?

技术上可行吗?你能解析node.js上的音频并进行实时混音吗?您是否认为服务器将同时爆发超过5个客户端?

Thanks

2 个解决方案

#1


4  

Yes, this is entirely possible, but as Sam pointed out, buffering is an issue. There is significant delay that builds up over several points:

是的,这完全有可能,但Sam指出,缓冲是一个问题。在几个方面存在显着的延迟:

  • Getting control commands from client
  • 从客户端获取控制命令

  • Mixing raw PCM audio into an internal buffer
  • 将原始PCM音频混合到内部缓冲区中

  • Encoding data with the correct codec (requires you to do this in chunks)
  • 使用正确的编解码器编码数据(要求您以块的形式执行此操作)

  • Sending audio data
  • 发送音频数据

  • Buffering client-side
  • Playback buffer on client-side
  • 客户端的播放缓冲区

Add this all up, and even if you get it working very quickly, you're still looking at a couple seconds delay.

加上这一切,即使你让它快速运行,你仍然会看到几秒钟的延迟。

If you do decide to go this route, you'll need an external application (or write your own Node extension) to do the mixing and encoding for you. Sox is probably a decent choice, and FFMPEG includes many codecs for your use. You can use both over STDIO.

如果您决定采用这种方式,则需要外部应用程序(或编写自己的Node扩展名)来为您进行混合和编码。 Sox可能是一个不错的选择,FFMPEG包含许多编解码器供您使用。您可以使用STDIO。

Regarding server load... this is not a light-weight kind of process, but you would have to profile it to see how bad it really is. I suggest you make other attempts at playing multiple audio streams at once client-side before attempting something like this.

关于服务器负载......这不是一个轻量级的过程,但你必须对其进行分析,看看它有多糟糕。我建议你在尝试这样的事情之前尝试在客户端播放多个音频流。

#2


0  

Please refer to this link. it works as expected but the issue is client control NodeJS Streaming for Audio/Video with Client Side Control

请参阅此链接。它按预期工作,但问题是客户端控制NodeJS Streaming for Audio / Video with Client Side Control

https://*.com/questions/32012695/nodejs-streaming-for-audio-video-with-client-side-control

#1


4  

Yes, this is entirely possible, but as Sam pointed out, buffering is an issue. There is significant delay that builds up over several points:

是的,这完全有可能,但Sam指出,缓冲是一个问题。在几个方面存在显着的延迟:

  • Getting control commands from client
  • 从客户端获取控制命令

  • Mixing raw PCM audio into an internal buffer
  • 将原始PCM音频混合到内部缓冲区中

  • Encoding data with the correct codec (requires you to do this in chunks)
  • 使用正确的编解码器编码数据(要求您以块的形式执行此操作)

  • Sending audio data
  • 发送音频数据

  • Buffering client-side
  • Playback buffer on client-side
  • 客户端的播放缓冲区

Add this all up, and even if you get it working very quickly, you're still looking at a couple seconds delay.

加上这一切,即使你让它快速运行,你仍然会看到几秒钟的延迟。

If you do decide to go this route, you'll need an external application (or write your own Node extension) to do the mixing and encoding for you. Sox is probably a decent choice, and FFMPEG includes many codecs for your use. You can use both over STDIO.

如果您决定采用这种方式,则需要外部应用程序(或编写自己的Node扩展名)来为您进行混合和编码。 Sox可能是一个不错的选择,FFMPEG包含许多编解码器供您使用。您可以使用STDIO。

Regarding server load... this is not a light-weight kind of process, but you would have to profile it to see how bad it really is. I suggest you make other attempts at playing multiple audio streams at once client-side before attempting something like this.

关于服务器负载......这不是一个轻量级的过程,但你必须对其进行分析,看看它有多糟糕。我建议你在尝试这样的事情之前尝试在客户端播放多个音频流。

#2


0  

Please refer to this link. it works as expected but the issue is client control NodeJS Streaming for Audio/Video with Client Side Control

请参阅此链接。它按预期工作,但问题是客户端控制NodeJS Streaming for Audio / Video with Client Side Control

https://*.com/questions/32012695/nodejs-streaming-for-audio-video-with-client-side-control