ubuntu + rtmp + ffmpeg(硬解码) + 树莓派实现视频直播(第一步)

1. 编译安装nginx

  a. 如果以前通过apt-get安装了nginx,需要卸载(sudo apt remove nginx)
  b. 去官网下载nginx http://nginx.org/en/download.html(我用的是1.12)

  c. 下载nginx-rtmp-module

    官方github地址:https://github.com/arut/nginx-rtmp-module

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

  d. 解压下载的nginx,进入nginx目录,写一个配置脚本config_nginx_1.12.sh内容如下:
  
./configure --prefix=/usr/local/nginx \
  --add-module=../nginx-rtmp-module \
  --with-http_flv_module \
  --with-http_mp4_module \
  执行:chmod +x config_nginx_1.12.sh
          ./config_nginx_1.12.sh
  会报出如下错误:
 
 ./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
意思就是HTTP rewrite模块需要PCRE 库,要么你加个不要这个模块的选项重新配置nginx,要么就安装PCRE。当然必须选择安装PCRE。

sudo apt install libpcre3 libpcre3-dev

系统报告libpcre3早就装好了,其实只需要装开发库libpcre3-dev。
重新配置,这次报告是需要OpenSSL,继续装:

sudo apt install openssl libssl-dev

系统报告openssl早就装好了,已经是最新版本了,想来还是跟PCRE一样,只需要装个开发库。

继续./config_nginx_1.12.sh
然后 make 
sudo make install

2. 配置nginx

sudo vim /usr/local/nginx/conf/nginx.conf

在最下面添加如下内容:

rtmp {
    server {
        listen 1935;  #监听的端口
        chunk_size 4000;
        application hls {  #rtmp推流请求路径: rtmp://ipaddress:1935/hls
            live on;
            hls on;
            hls_path /usr/local/nginx/html/hls;
            hls_fragment 5s;
         }    
    }    
}
这里的视频流目录:hls_path设置为 /usr/local/nginx/html/hls,这个目录的权限用chmod设置为775。

3. 启动nginx

cd /usr/local/nginx/sbin
sudo ./nginx -t
sudo ./nginx

猜你喜欢

转载自blog.csdn.net/cin_ie/article/details/80008851