栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

ubuntu安装部署nginx、rtmp、hls视频流

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ubuntu安装部署nginx、rtmp、hls视频流

1.下载nginx
wget http://nginx.org/download/nginx-1.14.0.tar.gz

2.安装依赖
// gcc、g++依赖库
sudo apt-get install build-essential
sudo apt-get install libtool

// pcre依赖库(http://www.pcre.org/)
sudo apt-get install libpcre3 libpcre3-dev

// zlib依赖库(http://www.zlib.net)
sudo apt-get install zlib1g-dev

// ssl依赖库
sudo apt-get install build-essential libtool libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev


3.下载rtsp扩展
sudo mkdir module && cd module
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
unzip master.zip 

4.解压编译
sudo tar -zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0/
sudo ./configure --prefix=/usr/local/nginx/ --add-module=/etc/module/nginx-rtmp-module-master --with-http_ssl_module
sudo make
sudo make install


5.创建系统服务文件
sudo vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target

6.配置nginx
sudo vim /usr/local/nginx/conf/nginx.conf


rtmp{
    server{
        listen 1935;
        
        application live{
            live on;
        }
        application hls{
            live on;
            hls on;
            #hls_path /home/hls/test;
            hls_fragment 3s;
            record off;
        }
    }
}


如果是hls,在http的server里增加
location /hls{
    add_header Access-Control-Allow-Origin *;
    types{
        application/vnd.apple.mpegurl m3u8; 
        video/mp2t ts;
    }
    alias /home/hls/test/;
    expires -1;
    add_header Cache-Control no-cache;
}

7.重启服务

sudo systemctl restart nginx.service

8.安装ffmpeg

sudo apt-get install ffmpeg

9.ffmpeg推流

rtsp转rtmp

sudo ffmpeg -rtsp_transport tcp -i "rtsp://admin:admin123@10.10.2.2:554/h264/ch1/main/av_stream" -f flv -r 25 -s 1920*1080 -an "rtmp://10.10.3.180:1935/live/test"

rtsp转hls

sudo ffmpeg -rtsp_transport tcp -i "rtsp://admin:admin123@10.10.2.2:554/h264/ch9/main/av_stream" -c copy -f hls  -hls_time 3.0 -hls_list_size 2 -hls_wrap 1200 /home/hls/test/test.m3u8

mp4转hls
sudo ffmpeg -i "http://10.10.3.71:8906/1.mp4" -c:v libx264 -c:a aac -strict -2 -hls_time 4 -hls_list_size 6  -hls_wrap 4  -f hls /home/hls/test/test.m3u8

10.网页访问

  
  
  
      
    demo  
	
	

 

    
  

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/882738.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号