在windows下搭建基于nginx的直播
标签(空格分隔): rtmp nginx ffmpeg
一、软件准备
1.nginx_1.7.11.3 Gryphon
2.stat.xsl
3.ffmpeg、ffplay
二、nginx配置文件conf/nginx.conf
worker_processes 1;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
application hls {
live on; #启用rtmp直播
#地址为rtmp://[server]:[rtmp_port]/[app]/[stream]
hls on; #启用hls直播
#地址为http://[server]:[http_port]/[app]/[stream].m3u8
#需要配合下面http段设置使用
hls_path nginx-rtmp-module/tmp/app/;
hls_fragment 5s;
recorder rec { #启用录制
record all manual; #手动控制录制启停
record_suffix _rec.flv;
record_path nginx-rtmp-module/tmp/rec/; #录制保存地址
record_unique on;
}
}
application vod2{ #rtmp点播
play nginx-rtmp-module/tmp/rec/;
}
}
}
http {
server {
listen 18080;
location /stat { #服务器状态
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root nginx-rtmp-module/;
}
location /control { #控制器
rtmp_control all;
}
location /hls/ { #hls直播地址
#server hls fragments
types{
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias nginx-rtmp-module/tmp/app/;
expires -1;
}
location /vod/{ #hls点播地址
alias nginx-rtmp-module/tmp/rec/;
}
location / {
root nginx-rtmp-module/www/;
}
}
}
nginx 命令
nginx.exe 启动
nginx -s reload //重启
nginx -s stop //停止
taskkill /IM /F nginx.exe //kill进程
ffmpeg 命令
ffmpeg -i "rtmp://www.scbtv.cn/live/new/ live=1" -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://127.0.0.1/hls/mystream
个人理解(个人笔记,未必正确)
因为需要支持苹果手机web端 ,视频需要采用libx264 (h264)和 音频 libfaac(acc)编码;
-i 输入流
-vcodec -acodec 和 -c:a -c:v 写法一样,表示视音频编码方式
rtmp输入流时需要双引号和live=1
-re i input.mp3 表示本地媒体文件
参考资料
http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/
http://blog.csdn.net/tao_627/article/details/22271559
http://superuser.com/questions/199751/where-can-i-download-ffmpeg-with-libfaac