1.资源包下载地址:https://pan.baidu.com/s/1CjXIRBghH4BbjQXIk9rTyA
2.解压:nginx-1.7.11.3-stream.zip 到合适位置,使用cmd进入解压后的目录,运行命令:
nginx.exe -c conf\nginx-win-rtmp.conf
3.解压 ffmpeg.zip 放到合适位置,将加压后的bin目录加入到环境变量:
4.打开cmd,想nginx推流:
ffmpeg -re -i D:\installed\ffmpeg\orange.mp4 -vcodec libx264 -acodec aac -f flv rtmp://127.0.0.1:1935/live/home
5.解压 VLCmediaplayerX64.zip ,打开播放器,点击【媒体】>>【打开网络串流】,将推流地址填进去,点击在点击【播放】
6.注意:播放的时候,需要确保ffmpeg正在推流,否则就没有内容可以播放:
7.发布hls流完整的配置:
#user nobody;
# multiple workers works !
worker_processes 2;
events {
worker_connections 8192;
}
rtmp {
server {
listen 1935;
chunk_size 4000;
application live {
live on;
hls on;
hls_path D:/installed/nginx-1.7.11.3-stream/video/hls;
hls_fragment 5s;
# 保存视频
recorder rec1{
record all;
record_unique on;
record_path D:/installed/nginx-1.7.11.3-stream/video/record;
record_suffix -%Y-%m-%d-%H_%M_%S.mp4;
}
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile off;
server_names_hash_bucket_size 128;
## Start: Timeouts ##
client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 30;
send_timeout 10;
keepalive_requests 10;
## End: Timeouts ##
server {
listen 80;
server_name localhost;
location / {
root D:/installed/nginx-1.7.11.3-stream/video;
index index.html index.htm;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root nginx-rtmp-module/;
}
location /control {
rtmp_control all;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
8.HTML5播放视频示例:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>HTML5播放视频</title>
</head>
<body>
<video width="352" height="288" controls>
<source src="http://192.168.1.106/hls/home.m3u8" type="application/vnd.apple.mpegurl">
浏览器不支持 video 标签。
</video>
</body>
</html>