1 2
   | brew tap denji/nginx brew install nginx-full --with-rtmp-module
 
  | 
 
配置nginx.conf,路径/opt/homebrew/etc/nginx/nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
   | rtmp {     server {         listen 1935;         chunk_size 4096;
          # live on         application rtmp_live {             live on;             # hls on; #这个参数把直播服务器改造成实时回放服务器。             # wait_key on; #对视频切片进行保护,这样就不会产生马赛克了。             # hls_path ./sbin/html; #切片视频文件存放位置。             # hls_fragment 10s;     #每个视频切片的时长。             # hls_playlist_length 60s;  #总共可以回看的时间,这里设置的是1分钟。             # hls_continuous on; #连续模式。             # hls_cleanup on;    #对多余的切片进行删除。             # hls_nested on;     #嵌套模式。         }
          # play videos         application rtmp_play{             play ./videos;  #build directory         }     } }
 
  | 
 
更多配置参考:example-nginxconf
重启 nginx
1 2 3 4 5 6 7 8
   | Reload config:  $ nginx -s reload Reopen Logfile:  $ nginx -s reopen Stop process:  $ nginx -s stop Waiting on exit process  $ nginx -s quit
 
  | 
 
使用ffmpeg 推流
1
   | ffmpeg -re -i test.flv -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://localhost:1935/$app/$name
 
  | 
 
上面定义的app叫rtmp_live,假设name=video
1
   | ffmpeg -re -i test.flv -vcodec libx264 -acodec aac -strict -2 -f flv rtmp:
 
  | 
 
使用ffplay拉流或者vlc拉流
1
   | ffplay rtmp://localhost:1935/rtmp_live/video
 
  | 
 
参考:
MACOS上搭建nginx+rtmp环境