您的位置:首页 > 运维架构 > Nginx

树莓派nginx+rtmp搭建直播流媒体服务

2018-03-12 00:00 639 查看
首先去现在nginx

http://nginx.org/en/download.html

下载nginx模块rtmp

git clone https://github.com/arut/nginx-rtmp-module.git[/code] 解压进入nginx目录,开始编译nginx

# 先安装rtmp依赖包
sudo apt install libpcre3-dev libssl-dev

./configure --prefix=/usr/local/share/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module
make && 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.m3u8 
ffplay rtmp://127.0.0.1:1935/hls/live
# 或者浏览器访问 http://127.0.0.1:99/hls/live.m3u8[/code] 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐