nginx 搭建http-flv(rtmp)流媒体
https://github.com/winshining/nginx-http-flv-module/blob/master/README.CN.md
git clone https://github.com/arut/nginx-http-flv-module
yum -y install openssl openssl-devel
wget http://nginx.org/download/nginx-1.10.3.tar.gz
tar -zxvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
//添加rtmp和openssl支持
./configure --add-module=/绝对路径/nginx-http-flv-module --with-http_ssl_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
nginx 启动
nginx -s reload 重启
nginx -s stop 停止
vim /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 4;
#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_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 模块在 access.log 中记录日志的间隔时间,对调试非常有用
log_size 1m; #log 模块用来记录日志的缓冲区大小
server {
listen 54321 reuseport;
server_name _;
application myapp {
live on;
meta off;# 为了兼容网页前端的 flv.js,设置为 off 可以避免报错
gop_cache on; # 支持GOP缓存,以减少首屏时间
allow play all; # 允许来自任何 ip 的人拉流
}
}
}
http {
include mime.types;
default_type application/octet-stream;
keepalive_timeout 65;
server {
listen 80;
server_name _;
location /live {
flv_live on;
chunked_transfer_encoding on; #支持'Transfer-Encoding: chunked'方式回复
add_header 'Access-Control-Allow-Origin' '*'; #添加额外的 HTTP 头
add_header 'Access-Control-Allow-Credentials' 'true'; #添加额外的 HTTP 头
}
}
}
nginx -s reload
推流
1.ffmpeg -re -i C:\Users\EDY\Desktop\1.mp4 -vcodec libx264 -acodec aac -f flv rtmp://122.112.245.213:54321/myapp/video_test
ffmpeg -re -i \
本地视频路径 \
-vcodec libx264 -acodec aac -f flv \
rtmp://服务器ip:端口/rtmp的路由匹配/自定义
2. ffmpeg -re -i "video" -c:v copy -c:a aac -b:a 192k -strict -2 -f flv "rtmp"
视频加水印,水印位置默认在右上角
3. ffmpeg -re -i "video" -i "image" -filter_complex overlay=W-w-5:5 -c:v libx264 -c:a aac -b:a 192k -strict -2 -f flv "rtmp"
拉流
http://122.112.245.213/live?port=54321&app=myapp&stream=video_test
live为拉流地址路由匹配,
port等于推流的端口号
app等于推流的路由
stream等于推流后自定义的文件名