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

开发环境

  • Ubuntu
  • nginx
  • nginx-rtmp-module
  • VLC media player

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)平台,用于快速开发、部署物联设备接入项目,是一整套物联系统解决方案。

你可能感兴趣的:(Java)