简体   繁体   English

如何使用 WebRTC 将视频流式传输到 RTMP?

[英]How to use WebRTC to stream video to RTMP?

I am trying to build a service that streams your screen from a browser to clients (something like twitch).我正在尝试构建一项服务,将您的屏幕从浏览器流式传输到客户端(类似于 twitch)。

What I have accomplished is I have built a working nginx server with rtmp, I tested it using OBS.我已经完成的是我用 rtmp 构建了一个工作的 nginx 服务器,我使用 OBS 对其进行了测试。 That works pretty well.这很好用。

And my question is how to stream a screen from a browser (not from OBS or other broadcasters) using WebRTC to nginx server with RTMP?我的问题是如何使用 WebRTC 将屏幕从浏览器(而不是 OBS 或其他广播公司)流式传输到带有 RTMP 的 nginx 服务器?

For RTSP<->WebRTC / RTMP<->WebRTC conversions, you need to run some kind of WebRTC gateway / media server software that works with all these formats/protocols and can transmux between all of them.对于 RTSP<->WebRTC / RTMP<->WebRTC 转换,您需要运行某种 WebRTC 网关/媒体服务器软件,该软件适用于所有这些格式/协议,并且可以在所有这些格式/协议之间进行传输。 Try Wowza / Unreal Media Server / Flashphoner.试试 Wowza / Unreal Media Server / Flashphoner。 https://en.wikipedia.org/wiki/Comparison_of_streaming_media_systems https://en.wikipedia.org/wiki/Comparison_of_streaming_media_systems

So in your case you want to publish the screen from browser to media server via WebRTC (H264 codec is a must) and then pull RTMP stream from the media server to nginx server with nginx-rtmp module.因此,在您的情况下,您想通过 WebRTC 将屏幕从浏览器发布到媒体服务器(H264 编解码器是必须的),然后使用 nginx-rtmp 模块将 RTMP 流从媒体服务器拉到 nginx 服务器。

Note that the opposite is possible too: You could push a stream to media server via RTMP, (for example, OBS screen capture) and then send this stream from media server to web browser(s) via WebRTC.请注意,反之亦然:您可以通过 RTMP 将流推送到媒体服务器(例如 OBS 屏幕截图),然后通过 WebRTC 将此流从媒体服务器发送到 Web 浏览器。

The main issue in these conversions is codec compatibility: H264 must be used for video, but if you need audio then you will have to do Opus to AAC transcoding.这些转换的主要问题是编解码器兼容性:视频必须使用 H264,但如果您需要音频,则必须将 Opus 转码为 AAC。

SRS(Simple Realtime Server) is also able to covert WebRTC to RTMP, vice versa. SRS(Simple Realtime Server)也能够将 WebRTC 转换为 RTMP,反之亦然。

WebRTC to RTMP is used for H5 publisher for live streaming. WebRTC to RTMP用于 H5 发布者进行直播。 Because RTMP is disable now(at 2021.12), so the only way to publish stream by H5 is WebRTC.因为RTMP现在被禁用(在2021.12),所以H5发布流的唯一方法是WebRTC。 We also need to covert WebRTC to RTMP, which enable us to reuse the stream by other platform.我们还需要将 WebRTC 转换为 RTMP,这样我们就可以复用其他平台的流。

And SRS also support RTMP to WebRTC , which is low latency live streaming.并且 SRS 还支持RTMP to WebRTC ,这是低延迟的实时流媒体。 Generally, RTMP is about 3~5s latency, while RTMP to WebRTC is about 0.8~1s latency.一般RTMP在3~5s延迟左右,而RTMP to WebRTC0.8~1s左右延迟。 Note that RTMP is not supported by H5, but HTTP-FLV works well.请注意,H5 不支持 RTMP,但HTTP-FLV运行良好。

Apart of this, SRS also support HTTP-FLV, which enable H5 to play the RTMP, by flv.js .除此之外,SRS 还支持 HTTP-FLV,通过flv.js使 H5 能够播放 RTMP。 The latency is also lower than HLS or LLHLS.延迟也低于 HLS 或 LLHLS。

Note: Other live streaming features are also important, because of off-topic, so please check the wiki of SRS, like DVR-MP4, DASH, Cluster, HTTP-API, etc.注意:其他直播功能也很重要,因为跑题了,所以请查看 SRS 的 wiki,如 DVR-MP4、DASH、Cluster、HTTP-API 等。

It's also OK to use nginx to pull RTMP stream from SRS, or let SRS to forward RTMP to nginx, after covert WebRTC to RTMP stream by SRS.也可以用Nginx从SRS拉RTMP流,或者让SRS把RTMP转发给Nginx,通过SRS将WebRTC隐蔽到RTMP流之后。

Please don't use WebRTC to do live streaming, unless you know what you're doing, please read Why and Why NOT use WebRTC for live streaming .请不要使用 WebRTC 进行直播,除非您知道自己在做什么,否则请阅读为什么以及为什么不使用 WebRTC 进行直播

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何直接从我的 WebRTC 到 Facebook RTMP 服务器的 stream 视频? - How to stream video from my WebRTC to Facebook RTMP server directly? 如何设置接受 RTMP 和/或 RTSP 流并使用 WebRTC 到 stream 到客户端(浏览器)的直播 Node js 服务器? - How to setup a livestream Node js server that accepts RTMP and/or RTSP streams and use WebRTC to stream to clients (browsers)? 将WebRTC流转发到rtmp服务器 - Forwarding WebRTC stream to a rtmp server webRTC:如何检测Stream中的音频/视频存在? - webRTC: How to detect audio/video presence in Stream? 如何在 WebRTC 中检测冻结的视频流 - How to detect a frozen video stream in WebRTC WebRTC - 如何在视频 stream 上调整麦克风音量? - WebRTC - How to adjust microphone volume on a video stream? WebRTC视频流错误 - WebRTC video stream error 如何在不提供凭据的情况下在浏览器中使用 Kinesis Video Stream WebRTC SDK? - How to use Kinesis Video Stream WebRTC SDK in the browser without providing credentials? 如何播放从WebRTC获得的HLS流(或其他视频流)? - How to play HLS stream (or other video stream) obtained from WebRTC? 我可以使用 WebRTC 接收标准 RTP 视频流吗? - Can I use WebRTC to receive a standard RTP video stream?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM