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