Nginx Intro - RTMP HLS
来源:互联网 发布:thunder mac破解 编辑:程序博客网 时间:2024/05/01 19:17
1. Nginx configuration
#user nobody;
worker_processes 1;
master_process off;
daemon off;
error_log logs/error.log debug;
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 4096;
application live {
live on;
record off;
}
application hls {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 5s;
}
}
}
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
}
application hls {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 5s;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
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"';
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
root html;
index index.html index.htm;
}
location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
}
#error_page 404 /404.html;
#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;
}
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# root html;
# index index.html index.htm;
# }
#}
}
2. push stream by ffmpeg
ffmpeg -f mpegts -re -i war.ts -c:v libx264 -s 640x360 -c:a libfdk_aac -ar 48000 -f flv rtmp://localhost/hls/test1
ffmpeg -f mpegts -re -i war.ts -c:v libx264 -s 640x360 -c:a libmp3lame -ar 48000 -f flv rtmp://localhost/hls/test
Notes: As far as mp3, flv not support mp3 with sample rate 48000. Following errors will be output.
[flv @ 0x96e340] FLV does not support sample rate 48000, choose from (44100, 22050, 11025)
[flv @ 0x96e340] Audio codec mp3 not compatible with flv
[flv @ 0x96e340] Audio codec mp3 not compatible with flv
If you change its sample rate from 48000 to 44100 as followings, it will be work normally.
ffmpeg -f mpegts -re -i war.ts -c:v libx264 -s 640x360 -c:a libmp3lame -ar 44100 -f flv rtmp://localhost/hls/test
3. pull stream by vlc
http://192.168.1.66/hls/test1.m3u8
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method ='OPTIONS') {
add_header 'Access-Control-Allow-Origin''*';
#
# Om nom nom cookies
#
add_header 'Access-Control-Allow-Credentials''true';
add_header 'Access-Control-Allow-Methods''GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers''DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age'1728000;
add_header 'Content-Type''text/plain charset=UTF-8';
add_header 'Content-Length'0;
return 204;
}
if ($request_method ='POST') {
add_header 'Access-Control-Allow-Origin''*';
add_header 'Access-Control-Allow-Credentials''true';
add_header 'Access-Control-Allow-Methods''GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers''DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
if ($request_method ='GET') {
add_header 'Access-Control-Allow-Origin''*';
add_header 'Access-Control-Allow-Credentials''true';
add_header 'Access-Control-Allow-Methods''GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers''DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
}
# Wide-open CORS config for nginx
#
location / {
if ($request_method ='OPTIONS') {
add_header 'Access-Control-Allow-Origin''*';
#
# Om nom nom cookies
#
add_header 'Access-Control-Allow-Credentials''true';
add_header 'Access-Control-Allow-Methods''GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers''DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age'1728000;
add_header 'Content-Type''text/plain charset=UTF-8';
add_header 'Content-Length'0;
return 204;
}
if ($request_method ='POST') {
add_header 'Access-Control-Allow-Origin''*';
add_header 'Access-Control-Allow-Credentials''true';
add_header 'Access-Control-Allow-Methods''GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers''DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
if ($request_method ='GET') {
add_header 'Access-Control-Allow-Origin''*';
add_header 'Access-Control-Allow-Credentials''true';
add_header 'Access-Control-Allow-Methods''GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers''DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
}
0 0
- Nginx Intro - RTMP HLS
- RTMP Protocol Intro - Nginx + RTMP
- nginx hls rtmp 环境搭建
- Nginx Intro - rtmp video stack infos
- Ubuntu12.04.3 配置nginx-rtmp支持HLS
- 使用Nginx-rtmp-module搭建hls直播
- Nginx RTMP配置文件种HLS部分
- HLS/MPEG-DASH/RTMP with nginx
- HLS/MPEG-DASH/RTMP with nginx
- HLS/MPEG-DASH/RTMP with nginx
- NGINX配置rtmp服务器实现rtmp以及hls直播
- NGINX配置rtmp服务器实现rtmp以及hls直播
- 利用nginx-rtmp-module搭建hls直播流媒体服务器
- 利用nginx搭建RTMP视频点播、直播、HLS服务器
- rtmp-nginx hls模式 m3u8文件丢失问题
- nginx rtmp & hls 直播流服务器搭建+防盗链
- 利用ffmpeg工具基于nginx-rtmp-module模块搭建HLS
- 利用nginx搭建RTMP视频点播、直播、HLS服务器
- TabLayout属性详解
- 【py交易】算法竞赛入门经典6.1.1卡片游戏 python
- hibernate查询
- opencv截图工具
- hibernate中多对一映射查询
- Nginx Intro - RTMP HLS
- 使用xargs与awk联合使用批量杀进程,很方便
- 打不开Spyder的原因
- HTTP Status 500 - Hibernate operation: could not insert: [com.qm.entity.Img]; uncategorized SQLExcep
- cifar10数据集的读取Python/Tensorflow
- ioremap
- read pragmatic programmer -- chapter6
- POJ 1008 Maya Calendar(日期模拟)
- androidstudio(起步篇)