H5 流媒体

协议

流实时消息协议(RTMP),Apple HTTP Live Streaming(HLS)和基于HTTP的动态自适应流(DASH)视频格式。

安装nginx rtmp模块

插件模式安装:

sudo apt-get install nginx-plus-module-rtmp

Put the load_module directive in the top‑level (“main”) context of NGINX Plus configuration file, nginx.conf:

load_module modules/ngx_rtmp_module.so;

编译安装:
依赖

sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

下载nginx源码和rtmp模块:

git clone https://github.com/nginx/nginx.git
git clone https://github.com/arut/nginx-rtmp-module.git

直接下载tar.gz:

wget 'https://github.com/nginx/nginx/archive/release-1.17.10.tar.gz'
wget 'https://github.com/arut/nginx-rtmp-module/archive/v1.2.1.tar.gz'
tar xvf release-1.17.10.tar.gz
tar xvf v1.2.1.tar.gz

编译:

cd nginx-release-1.17.10/auto
./configure --with-http_ssl_module --add-module=../../nginx-rtmp-module-dev
make

术语

应用程序:application live 表示rtmp://0.0.0.0/live
串流密钥:流名称,以及查询字符串。之间用?连接。
流名称:直播流的标识。

HLS

HLS对RTMP流进行切片,生成.ts片段到hls_path指令指定的目录中,并且自动维护一个.m3u8列表文件,我们只需要对这些文件的HTTP GET请求做处理就好。
文档:https://github.com/arut/nginx-rtmp-module/wiki/Directives#hls

直播延迟方案:
建议OBS用户将关键帧间隔减小,1~2s为佳。

事件

publish_notify on;
notify_method get;
on_publish http://127.0.0.1/api/live/auth;
on_publish_done http://127.0.0.1/api/live/auth;
on_play http://127.0.0.1/api/live/auth;
on_play_done http://127.0.0.1/api/live/auth;

https://blog.csdn.net/qq446252221/article/details/95648144

重要参考

https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/
https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/
https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/#options-1-from-existing-rtmp-stream-already-in-h264
https://www.shangmayuan.com/a/ba750734cf5b45bd9c9f576b.html

m3u8 示例:
https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8
m3u8 在线播放:
https://www.jwplayer.com/developers/web-player-demos/live-streaming/

END

原文地址:https://www.cnblogs.com/develon/p/12701590.html