使用 Flask 的 Nginx RTMP

Nginx RTMP with Flask

我已经按照 documentation/tutorial 了解如何从这里设置 RTMP 流式传输的配置文件:https://www.nginx.com/blog/video-streaming-for-remote-learning-with-nginx/ and it is pretty straight forward. However, I am not sure how I can have my backend built on Flask to redirect the stream to some HLS/DASH video player that is embedded in an HTML template that is sent in response to a client that requested for a specific HTTP endpoint. The tutorial shows how to view locally in a VLC media player but not how to embed it in an HTML file that gets sent to the client. How would I go about doing this? For reference, I am hosting my website on Heroku that is set up with its Nginx buildpack from here, https://github.com/heroku/heroku-buildpack-nginx,我不确定是否需要让 Heroku 安装额外的依赖项设置 RTMP 服务器并监听流。

使用 HLS 协议(HTTP 直播)。 Nginx 知道如何完美呈现 HTTP。因此,您只需要创建和更新 HLS 流的播放列表和片段,以及监控旧片段的删除。为此,有一个 nginx-rtmp-hls 模块。它位于 hls 目录中,但默认情况下不收集,因为需要 ffmpeg 包中包含的 libavformat 库。要构建支持 HLS 的 nginx,您需要在配置期间显式添加此模块:

./configure --add-module=/path/to/nginx-rtmp-module --add-module=/path/to/nginx-rtmp-module/hls

要生成 HLS,只需指定以下指令:

application myapp {
    live on;
    hls on;
    hls_path /tmp/hls;
    hls_fragment 5s;
}

最后,在 http{} 部分,配置与 HLS 相关的所有内容的 return:

location /hls {
    root /tmp;
}

要在浏览器中显示流,请创建 html 包含以下内容的页面(示例):

<video width="600" height="300" controls="1" autoplay="1" src="http://example.com/hls/mystream.m3u8"></video>

更新 1:

您在 Nginx 设置教程中附加了 link,所以我参考了他们的 "Compiling NGINX with the RTMP Module" 步骤,其中包含与 HLS 模块相关的更改:

$ cd /path/to/build/dir
$ git clone https://github.com/arut/nginx-rtmp-module.git
$ git clone https://github.com/nginx/nginx.git
$ cd nginx
$ ./auto/configure --add-module=../nginx-rtmp-module --add-module=../nginx-rtmp-module/hls
$ make
$ sudo make install