首先去现在nginx
http://nginx.org/en/download.html
下载nginx模块rtmp
git clone https://github.com/arut/nginx-rtmp-module.git
解压进入nginx目录,开始编译nginx
# 先安装rtmp依赖包sudo apt install libpcre3-dev libssl-dev./configure --prefix=/usr/local/share/nginx --add-module=../nginx-rtmp-module --with-http_ssl_modulemake && make install
nginx.conf配置
# 关键配置rtmp {server {listen 1935;chunk_size 4000;application hls {live on;hls on;hls_path /usr/local/share/nginx/html/hls; # 缓冲区目录hls_fragment 5s; # 设置HLS分段(切片)长度。默认为5秒钟}}}http {include mime.types;default_type application/octet-stream;sendfile on;server {listen 99;server_name localhost;location / {root /usr/local/share/nginx/html;index index.html index.htm;}}}
安装ffmpeg
sudo apt install ffmpeg
开始从摄像头推流
raspivid -o - -t 0 -vf -hf -w 640 -h 480 -fps 25 -b 500000 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -s 640x480 -strict experimental -f flv rtmp://0.0.0.0:1935/hls/live
测试直播
# 推流后得到地址# rtmp://127.0.0.1:1935/hls/live# http://127.0.0.1:99/hls/live.m3u8ffplay rtmp://127.0.0.1:1935/hls/live# 或者浏览器访问 http://127.0.0.1:99/hls/live.m3u8

