nginx-rtmp-module和simple-rtmp-server搭建

吉栋
2023-12-01

nginx-rtmp-module直播流搭建

a) 下载nginxnginx-rtmp-module,此处使用nginx-1.6.2.tar.gznginx-rtmp-module下载地址:https://github.com/arut/nginx-rtmp-module.git

b) 下载nginx依赖库pcre,openssl,此处我们使用pcre-8.36.tar.gzopenssl-1.0.1j.tar.gz

c) 分别解压nginx,pcre,opensslnginx-rtmp-module/home/stream_server目录下,进入nginx解压后的目录nginx-1.6.2

d) ./configure --prefix=/home/stream_server/nginx --with-pcre=../pcre-8.36 --with-http_stub_status_module --with-http_ssl_module --add-module=../nginx-rtmp-module --with-debug --with-openssl=../openssl-1.0.1j

e) make && make install

f) cd /home/stream_server/nginx目录,在conf目录下创建nginx_rtmp.conf,配置如下:

#user  nobody;

worker_processes  1;

error_log  logs/error.log debug;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections  1024;

}

rtmp {

    server {

        listen 1935;

        chunk_size 4096;

        application myapp {

            live on;

        }

    }

}

http {

    server {

        listen 8080;

        location /stat {

            rtmp_stat all;

            rtmp_stat_stylesheet stat.xsl;

        }

        location /stat.xsl {

            root /home/stream_server/nginx-rtmp-module/;

        }

        location /control {

            rtmp_control all;

        }

        location /rtmp-publisher {

            root /home/stream_server/nginx-rtmp-module/test;

        }

        location / {

            root /home/stream_server/nginx-rtmp-module/test/www;

        }

location /hls {

            # Serve HLS fragments

            types {

                application/vnd.apple.mpegurl m3u8;

                video/mp2t ts;

            }

            root /tmp;

            add_header Cache-Control no-cache;

        }

    }

}

g) 启动nginxcd /home/stream_server/nginx./sbin/nginx -c conf/nginx_rtmp.conf

h) 使用ffmpeg推送rtmpnginx-rtmp-serverffmpeg -re -i 1.flv -c:v libx264 -c:a copy -f flv rtmp://127.0.0.1:1935/myapp/live1

i) 检查rtmp服务状态,如下图所示。

j) 播放直播流,使用ffplayervlc等等播放,流服务器地址:192.168.9.192:1935

  ffplay -i rtmp://192.168.9.192:1935/myapp/live1

k) 播放成功。




simple-rtmp-server直播流搭建

simple-rtmp-server(简称srs)的编译搭建步骤如下:

本文srs的下载目录为/home/stream_server

a) 下载srs代码,git clone https://github.com/winlinvip/simple-rtmp-server.git

b) 进入simple-rtmp-server目录 cd /home/stream_server/simple-rtmp-server/trunk

c) ./configure --full

d) make 此时编译成功

e) 启动srs./objs/srs -c conf/demo.19350.conf

f) demo.19350.conf 配置如下:

listen              19350;

max_connections     1000;

daemon              on;

srs_log_tank        file;

srs_log_file        ./objs/srs.demo.19350.log;

pid                 ./objs/srs.demo.19350.pid;

vhost __defaultVhost__ {

    enabled         on;

    gop_cache       on;

    hls {

        enabled         on;

        hls_path        ./objs/nginx/html/forward;

        hls_fragment    5;

        hls_window      30;

    }

}

g) ffmpeg推送rtmp./ffmpeg -re -i 1.flv -c:v libx264 -c:a copy -f flv rtmp://127.0.0.1:19350/live/stream1

hffplay播放 ffplay -i rtmp://192.168.9.192:19350/live/stream1

 类似资料: