Simple Live System Using Nginx
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的更多相关文章
- 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 ...
- Simple GB28181 System
I. Deployment / Architecture Block Diagram II. Resources Used 1. freeswitch —— sip server and media ...
- 使用metricbeat监控system和nginx
下载并解压缩metricbeat metricbeat.yml配置文件设置: setup.kibana: host: "192.168.75.21:5601" output.ela ...
- Simple File System
This is my operating system class design. scanner.h #include<string> using namespace std; #pra ...
- Artix-7 50T FPGA试用笔记之Create a simple MicroBlaze System
前言:之前笔者的试用博文提到安富利这块板子非常适合MicroBlaze开发,同时网上关于MicroBlaze的资料非常少(或含糊不清),没有一篇能完整介绍VIVADO SDK的设计流程,所以笔者带来这 ...
- GB28181 To RTMP/HLS/HTTP-FLV/DASH Gateway
I. Deployment / Architecture Block Diagram II. Resources Used 1. freeswitch —— sip server https://f ...
- Nginx - Additional Modules, Content and Encoding
The following set of modules provides functionalities having an effect on the contents served to the ...
- CentOS7安装和配置Nginx(https)
安装Nginx下载安装包# wget http://nginx.org/download/nginx-1.11.7.tar.gz# tar -zxvf nginx-1.11.7.tar.gz# cd ...
- centos7 设置nginx和php开机自启动
nginx开机自启动 首先我是源码安装的,需要手动建立nginx.service服务文件 cd /lib/systemd/system touch nginx.service nginx.servic ...
随机推荐
- 【PowerOJ1739&网络流24题】魔术球问题(最大流)
题意: 思路: 0.[问题分析] 枚举答案转化为判定性问题,然后最小路径覆盖,可以转化成二分图最大匹配,从而用最大流解决. [建模方法] 枚举答案A,在图中建立节点1..A.如果对于i<j有i+ ...
- APK文件结构和安装过程
APK文件结构Android应用是用Java编写的,利用Android SDK编译代码,并且把所有的数据和资源文件打包成一个APK (Android Package)文件,这是一个后缀名为.apk的压 ...
- shell时间转换脚本
字符串转换为时间戳: time2utc #!/bin/sh Time=$ date -d "${Time}" '+%s' 时间戳转日期字符串 utc2time #!/bin/sh ...
- 冲刺周五——Fifth Day
#一.Fifth Day照片 #二.今日份燃尽图 #三.项目进展 * 码云团队协同环境构建完毕 * 利用Leangoo制作任务分工及生成燃尽图 * 完成AES加解密部分代码 * 用代码实现对文件的新建 ...
- h5视频标签 video
video标签,用来播放视频的 基本上所有的浏览器都支持 video支持的视频格式有: mp4 mime-type: video/mp4 WebM mime-type: video/WebM Ogg ...
- What is the difference between Kill and Kill -9 command in Unix?
w difference kill -9 pid and kill pid command - Ask Ubuntu https://askubuntu.com/questions/791841/d ...
- Vue知识整理3:v-once的使用
v-once可以使得数据绑定只绑定一次,后期不会再改变,如下图所示:
- 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_08 转换流_3_转换流的原理
FileReader源码的构造方法.底层使用FileInputStram读取 编码不一样占用的字节大小也不一样.GBK一个汉字占用 2个字节. utf-8一个汉字占用三个字节 转换流InputStre ...
- 阶段1 语言基础+高级_1-3-Java语言高级_04-集合_06 Set集合_5_HashSet存储自定义类型元素
想存储的元素不重复,就必须重写hashCode和equals这两个方法 新建一个Person类.添加姓名和年龄这两个成员变量..get和set,有参和无参构造. 重点是重写了toString的方法 自 ...
- 《计算机程式设计》Week2 课堂笔记
本笔记记录自 Coursera课程 <计算机程式设计> 台湾大学 刘邦锋老师 Week2 Control Structure 2-1 If-then-else if then 判断 if ...