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

首先去现在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_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

 

转载于:https://my.oschina.net/yehun/blog/1633459

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值