1. Install nginx

su
mkdir /usr/local/nginx
cd /usr/local/nginx
apt-get install libssl-dev
tar xvf nginx-http-flv-module-1.2.7.tar.gz
tar xvf nginx-1.17.5.tar.gz
cd nginx-1.17.5
./configure --with-http_ssl_module --add-module=../nginx-http-flv-module-1.2.7
make && make install

2. Edit  nginx.conf

cp nginx-http-flv-module-1.2.7/test/nginx.conf /usr/local/nginx/conf/

worker_processes  1;

error_log  logs/error.log debug;

events {
worker_connections 1024;
} rtmp {
server {
listen 1935; application myapp {
live on; #record keyframes;
#record_path /tmp;
#record_max_size 128K;
#record_interval 30s;
#record_suffix .this.is.flv; #on_publish http://localhost:8080/publish;
#on_play http://localhost:8080/play;
#on_record_done http://localhost:8080/record_done;
}
}
} http {
server {
listen 8002; location /live{
flv_live on;
} location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
} location /stat.xsl {
root /usr/local/nginx/nginx-http-flv-module-1.2.7/;
} location /control {
rtmp_control all;
} #location /publish {
# return 201;
#} #location /play {
# return 202;
#} #location /record_done {
# return 203;
#} location /rtmp-publisher {
root /usr/local/nginx/nginx-http-flv-module-1.2.7/test;
} location / {
root /usr/local/nginx/nginx-http-flv-module-1.2.7/test/www;
}
}
}

Reference example:

Example

Assume that listen directive specified in http block is:

http {
...
server {
listen 8080; #not default port 80
... location /live {
flv_live on;
}
}
} And listen directive specified in rtmp block is: rtmp {
...
server {
listen 1985; #not default port 1935
... application myapp {
live on;
}
}
}

3. Startup nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

#ps -ef|grep nginx
#kill -TERM 2132 or kill -INT 2132
#pkill -9 nginx
#./nginx -t
#./nginx -s reload

4. push rtmp stream

ffmpeg -re -i source.200kbps.768x320.flv -c copy -f flv rtmp://127.0.0.1:1935/myapp/mystream

5. player
rtmp://localhost:1935/myapp/mystream

http://localhost:8002/live?port=1935&app=myapp&stream=mystream

6. Other optimized configuration

worker_processes  10;
events {
worker_connections 10240;
}
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /tmp;
rtmp{
out_queue 4096;
out_cork 8;
max_streams 128;
timeout 15s;
drop_idle_publisher 15s;
log_interval 5s;
log_size 1m;
server{
listen 9000;
server_name 127.0.0.1;
application myapp{
live on;
gop_cache on;
}
application hls{
live on;
hls on;
hls_path /usr/local/nginx/html/hls;
}
application dash{
live on;
dash on;
dash_path /usr/local/nginx/html/dash;
} }
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8002;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /live{
flv_live on;
chunked_transfer_encoding on;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
}
location /hls{
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /usr/local/nginx/html/hls;
add_header 'Cache-Control' 'no-cache';
}
location /dash {
root /usr/local/nginx/html/dash;
add_header 'Cache-Control' 'no-cache';
} location /stat {
#configuration of push & pull status
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/local/nginx/nginx-http-flv-module-1.2.7;
} location /control {
rtmp_control all; #configuration of control module of rtmp
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
} }

rtmp

rtmp://example.com[:port]/myapp/mystream

hls
http://example.com[:port]/dir/streamname.m3u8

dash
http://example.com[:port]/dir/streamname.mpd

7. Reference design:

https://github.com/winshining/nginx-http-flv-module

https://blog.csdn.net/caowenjing123/article/details/94623466

Simple Live System Using Nginx的更多相关文章

  1. Building simple plug-ins system for ASP.NET Core(转)

    Recently I built plug-ins support to my TemperatureStation IoT solution web site. The code for .NET ...

  2. Simple GB28181 System

    I. Deployment  / Architecture Block Diagram II. Resources Used 1. freeswitch —— sip server and media ...

  3. 使用metricbeat监控system和nginx

    下载并解压缩metricbeat metricbeat.yml配置文件设置: setup.kibana: host: "192.168.75.21:5601" output.ela ...

  4. Simple File System

    This is my operating system class design. scanner.h #include<string> using namespace std; #pra ...

  5. Artix-7 50T FPGA试用笔记之Create a simple MicroBlaze System

    前言:之前笔者的试用博文提到安富利这块板子非常适合MicroBlaze开发,同时网上关于MicroBlaze的资料非常少(或含糊不清),没有一篇能完整介绍VIVADO SDK的设计流程,所以笔者带来这 ...

  6. GB28181 To RTMP/HLS/HTTP-FLV/DASH Gateway

    I. Deployment  / Architecture Block Diagram II. Resources Used 1. freeswitch —— sip server https://f ...

  7. Nginx - Additional Modules, Content and Encoding

    The following set of modules provides functionalities having an effect on the contents served to the ...

  8. CentOS7安装和配置Nginx(https)

    安装Nginx下载安装包# wget http://nginx.org/download/nginx-1.11.7.tar.gz# tar -zxvf nginx-1.11.7.tar.gz# cd ...

  9. centos7 设置nginx和php开机自启动

    nginx开机自启动 首先我是源码安装的,需要手动建立nginx.service服务文件 cd /lib/systemd/system touch nginx.service nginx.servic ...

随机推荐

  1. cookie、session和会话保持

    1.会话 在程序中,会话跟踪是很重要的事情.理论上,一个已登录用户,在这次登录后进行的所有请求操作都应该属于同一个会话,而另一个用户的所有请求操作则应该属于另一个会话,二者不能混淆.例如,用户 A 在 ...

  2. Java——static

    [static] <1>static成员变量存储在内存data segment区域,不是存放在堆中. <2>静态成员变量属于整个类,任何一个对象都可以访问这个值:如果没有对象, ...

  3. Miniprofiler在目中使用报 mini-profiler-resources/includes.js 404错误

    原因,没有配置webconfig <system.webServer> <modules> <remove name="FormsAuthentication& ...

  4. python 浮点运算

    print(format(float(a)/float(b),'.2f'))

  5. Linux内核调试方法总结之strace

    strace [用途] strace是一个功能强大的调试.分析.诊断工具,跟踪程序或进程执行时的系统调用和所接收的信号.可将所调用的系统调用的名称.参数和返回值输出到标准输出或者输出到-o指定的文件. ...

  6. Java的参数传递是值传递?

    引用传递和值传递的区别.(不先说定义的都是在耍流氓!) 按值调用(call by value) : 在参数传递过程中,形参和实参占用了两个完全不同的内存空间.形参所存储的内容是实参存储内容的一份拷贝. ...

  7. 关于问题的四个单词区别: question problem matter issue

    [[ 网上讨论的 problem, question, issue, matter这些名词均含"问题"之意.problem: 指客观上存在的.难以处理或难以理解的问题.questi ...

  8. 如何将阿里云上的RDS 备份的mysql数据还原到windows环境中

    一.本地mysql数据库创建与备份库一致的数据库名,如testdb: 二.本地创建与备份库一致的数据库表,记得设置ALTER TABLE tableName1 ROW_FORMAT = compact ...

  9. EDM营销必知:电子邮件打开和点击的几组数据

    在EDM营销中,了解一下电子邮件何时被打开和点击很重要.这有助于我们在合适的时间发送邮件出去,从而带来最大化的效果. 1.邮件打开的最高峰在早上8点至9点之间,其次是下午三点到四点.因此,在这个时间发 ...

  10. sqlalchemy批量添加数据-数据源是json(小算法)

    需求: 想要写1个增加case的接口 问题: sqlalchemy添加case的方式,只能是1条数据1条数据的插入,像这样: ro2 = Role(name='user') db.session.ad ...