RTSP转RTMP,Nginx和nginx-rtmp-module配置直播推流服务器

开发环境

Java实现自动转码推流服务代码推荐 dc3-rtmp

依赖

安装依赖库

sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev openssl libssl-dev

编译

配置&编译Nginx,使用默认配置,并添加nginx-rtmp模块。

./configure --add-module=../nginx-rtmp-module
make
sudo make install

Nginx 配置文件参考

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#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 4000;

        # TV mode: one publisher, many subscribers
        application rtmp {

            # enable live streaming
            live on;

            # record first 1K of stream
            record all;
            record_path /tmp/av;
            record_max_size 4K;

            # append current timestamp to each flv
            record_unique on;

            # publish only from localhost
            allow publish all;
            # deny publish all;

            #allow play all;
        }

        # video on demand
        application mp4 {
            play /var/mp4s;
        }
    }
}

# HTTP can be used for accessing RTMP stats
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        # This URL provides RTMP statistics in XML
        location /stat {
            rtmp_stat all;

            # Use this stylesheet to view XML as web page
            # in browser
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            # XML stylesheet to view RTMP stats.
            # Copy stat.xsl wherever you want
            # and put the full directory path here
            root /usr/local/nginx/nginx-rtmp-module/;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

常用的nginx命令

ngnix -s reload:表示重新加载配置文件
ngnix -s reopen: 再次打开日志文件
ngnix -s stop : 停止服务器
ngnix -s quit : 退出服务器

启动nginx服务

sudo /usr/local/nginx/sbin/nginx

安装obs-studio开始第一次推流

sudo add-apt-repository ppa:obsproject/obs-studio
sudo apt-get update && sudo apt-get install obs-studio
配置流地址
rtmp://192.168.1.102:1935/onzhou/live

安装vlc播放器开始拉流

sudo apt install vlc

项目推荐



DC3是基于Spring Cloud的开源可分布式物联网(IOT)平台,用于快速开发、部署物联设备接入项目,是一整套物联系统解决方案。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值