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. Element ui 中的Upload用法

    效果图: 代码:

  2. BZOJ 1029 建筑抢修(贪心堆)

    原题代号:BZOJ 1029 原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1029 原题描述: 建筑抢修 小刚在玩JSOI提供的一个称之为 ...

  3. RedisTemplate访问Redis数据结构(一)——String

    当对String数据结构进行操作时,推荐直接使用spring-data-redis提供的StringRedisTemplate,其配置如下 <bean id="stringRedisT ...

  4. 如何快速优雅的解决:ORA-02290: 违反检查约束条件 异常问题

    在向oracle保存数据时,控制台报错如下: 很明显是保存时,该表的设计不允许某个字段非空导致的,但由于该表的数量较多,采用断点的方式有太过麻烦, 这里笔者采用 oracle 的客户端连接工具orac ...

  5. 为什么Redis可以方便地实现分布式锁

    1.Redis为单进程单线程模式,采用队列模式将并发访问变成串行访问,且多客户端对Redis的连接并不存在竞争关系. 2.Redis的SETNX命令可以方便的实现分布式锁. setNX(SET if  ...

  6. 关于编译GITHUB上的工程

    对于WINDOWS用户,很多人都不习惯使用cmake或makefile编译工程,对于GITHUB上的工程如何编译成熟悉的visual studio文件常常感到困难. 而且,GITHUB上的不少工程本身 ...

  7. Python 代码控制Windows定时关机

    为了在规定时间内实现电脑关机,我使用python编写了几行代码,最简单的实现了关机操作,后续再进行其它功能的添加(操作页面,取消等) import os,time #获取命令行输入的关机时间 inpu ...

  8. Python Django的安装配置

    学习Django前,我们要确定电脑上是否已经安装了Python,目前Python有两个版本,不过这两个版本并不互相兼容,所以根据个人选择合适的版本. 因为从Django2.0开始将不再支持Python ...

  9. 剑指 Offer——数组中的逆序对

    1. 题目 2. 解答 借助于归并排序的分治思想,在每次合并的时候统计逆序对.因为要合并的两个数组都是有序的,如果左半部分数组当前值大于右半部分数组当前值,那么左半部分数组当前值右边的数就都大于右半部 ...

  10. mongodb 语法小结

    数据库 一个mongodb中可以建立多个数据库. MongoDB的默认数据库为"db",该数据库存储在data目录中. MongoDB的单个实例可以容纳多个独立的数据库,每一个都有 ...