树莓派编译nginx,支持rtmp直播

  • 树莓派3B+
  • 系统更新至最新
  1. 下载依赖
sudo apt-get update
sudo apt-get install libxslt1-dev libgd-dev libgeoip-dev libpam0g-dev git-core libpcre3-dev libssl-dev git-core vim
  1. 下载源代码
    本来应该到官网去下载的,需要添加rtmp模块,为了方便操作,我将模块和nginx源码整合了
git clone https://git.dev.tencent.com/BDZNH/nginx.git
mkdir -p /var/lib/nginx/body
mkdir -p /var/lib/nginx/fastcgi
mkdir -p /var/lib/nginx/proxy
mkdir -p /var/lib/nginx/scgi
mkdir -p /var/lib/nginx/uwsgi
  1. 编译
cd nginx/

./configure \
--with-cc-opt='-g -O2 -fdebug-prefix-map=./=. -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' \
--with-ld-opt='-Wl,-z,relro -Wl,-z,now' \
--sbin-path=/usr/bin/ \
--prefix=/usr/share/nginx \
--conf-path=/etc/nginx/nginx.conf \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log \
--lock-path=/var/lock/nginx.lock \
--pid-path=/run/nginx.pid \
--modules-path=/usr/lib/nginx/modules \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--with-debug \
--with-pcre-jit \
--with-ipv6 \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-http_v2_module \
--with-http_dav_module \
--with-http_slice_module \
--with-threads \
--with-http_addition_module \
--with-http_geoip_module=dynamic \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module=dynamic \
--with-http_sub_module \
--with-http_xslt_module=dynamic \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-mail=dynamic \
--with-mail_ssl_module \
--add-dynamic-module=./debian/modules/nginx-auth-pam \
--add-dynamic-module=./debian/modules/nginx-dav-ext-module \
--add-dynamic-module=./debian/modules/nginx-echo \
--add-dynamic-module=./debian/modules/nginx-upstream-fair \
--add-dynamic-module=./debian/modules/ngx_http_substitutions_filter_module \
--add-module=./debian/modules/nginx-rtmp-module

make -j4 && sudo make install 

4.配置
将以下内容添加到"/etc/nginx/nginx.conf"

rtmp {
    server {
        listen 1935;

        application live {
            live on;
        }
    }
}
  1. 使用
sudo nginx -t

输出都为ok的时候表示可以用了,去 http://www.ffmpeg.org/download.html 下载好ffmpeg,使用命令

ffmpeg -re -i "source.mp4" -c copy -f flv "rtmp://pi_ip:1935/live"

即可推流
使用 potplayer 或者 vlc player ,从"rtmp://pi_ip:1935/live" 即可串流

posted @ 2019-02-12 15:35  SupperMary  阅读(1403)  评论(0编辑  收藏  举报