樹莓派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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章