1.安装nginx
brew tap denji/homebrew-nginx
brew install nginx-full --with-rtmp-module
查看nginx配置: brew info nginx-full
2.配置nginx和rtmp
找到nginx.conf文件在最后一行加入:
rtmp {
server {
listen 1935;
application live1 {
live on;
record off;
}
}
}
重启nginx: nginx -s reload
3.配置nginx和hls
http 和 rtmp中分别添加
location /hls {
#Serve HLS config
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /usr/local/var/www;
add_header Cache-Control no-cache;
}
application hls{
live on;
hls on;
hls_path /usr/local/var/www/hls;
hls_fragment 1s;
}
4.安装ffmpeng
安装: brew install ffmpeng
ffmpeng推rtmp流: ffmpeg -re -i /data/hls/mp4/234.mp4 -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://localhost:1935/live1/room
ffplay播放: ffplay "rtmp://localhost:1935/live1/room" 局域网播放:ffplay "rtmp://电脑ip:1935/live1/room"
ffmpeng推hls流: ffmpeg -re -i 视频的据对路径 -vcodec copy -acodec copy -f flv rtmp://localhost:1935/hls/room
ffplay播放 :ffplay "http://localhost:1935/hls/room.m3u8"
5.http点播
前往文件夹/data/hls/m3u8,将要点播的视频拖入到文件夹下。
打开浏览器: http://电脑的ip:8080/123.mp4