3 月,跳不动了?>>> 树莓派nginx rtmp搭建直播流媒体服务 - yehun - OSCHINA - 图1

    首先去现在nginx

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

    下载nginx模块rtmp

    1. git clone https://github.com/arut/nginx-rtmp-module.git

    解压进入nginx目录,开始编译nginx

    1. # 先安装rtmp依赖包
    2. sudo apt install libpcre3-dev libssl-dev
    3. ./configure --prefix=/usr/local/share/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module
    4. make && make install

    nginx.conf配置

    1. # 关键配置
    2. rtmp {
    3. server {
    4. listen 1935;
    5. chunk_size 4000;
    6. application hls {
    7. live on;
    8. hls on;
    9. hls_path /usr/local/share/nginx/html/hls; # 缓冲区目录
    10. hls_fragment 5s; # 设置HLS分段(切片)长度。默认为5秒钟
    11. }
    12. }
    13. }
    14. http {
    15. include mime.types;
    16. default_type application/octet-stream;
    17. sendfile on;
    18. server {
    19. listen 99;
    20. server_name localhost;
    21. location / {
    22. root /usr/local/share/nginx/html;
    23. index index.html index.htm;
    24. }
    25. }
    26. }

    安装ffmpeg

    1. sudo apt install ffmpeg

    开始从摄像头推流

    1. 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

    测试直播

    1. # 推流后得到地址
    2. # rtmp://127.0.0.1:1935/hls/live
    3. # http://127.0.0.1:99/hls/live.m3u8
    4. ffplay rtmp://127.0.0.1:1935/hls/live
    5. # 或者浏览器访问 http://127.0.0.1:99/hls/live.m3u8