nginx 安装rtmp模块实现推流服务器

编辑于 2022-10-13 11:34 阅读 159

安装模块

请移步 https://www.cuiwei.net/p/1011052604

配置文档 https://github.com/arut/nginx-rtmp-module/wiki/Directives

vi /etc/nginx/nginx.conf

load_module modules/ngx_rtmp_module.so;
events {
    worker_connections  1024;
}
rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application rtmp-live {
            live on;
        }
    }
}

http {
...
}

推流测试

ffmpeg 命令行推流

ffmpeg -re -stream_loop -1 -i ./test.flv -c copy -f flv rtmp://127.0.0.1:1935/rtmp-live/test

OBS推流

WX202210022132542x.png

拉流测试

VLC

容易失败,失败就多试几次

WX202210022132012x.png

hls.js

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/hls.js/latest/hls.min.js"></script>
</head>
<body>
<video id="video" controls autoplay></video>
<script>
    if(Hls.isSupported()) {
        var video = document.getElementById('video');
        var hls = new Hls();
        hls.loadSource('https://pull-hls-f96.douyincdn.com/stage/stream-399947309713982122_or4.m3u8');
        hls.attachMedia(video);
        hls.on(Hls.Events.MANIFEST_PARSED,function() {
            video.play();
        });
    }
</script>
</body>
</html>

广而告之,我的新作品《语音助手》上架Google Play了,欢迎下载体验