nginx的nginx-rtmp-module应用

1、下载nginx:

nginx的官方网站为:nginx: download

解压:

tar xvf nginx-1.10.3.tar.gz

2、安装nginx依赖运行包命令: 

 sudo apt-get install libssl-dev
 sudo apt-get install libpcre3 libpcre3-dev

3、下载nginx-rtmp-module:

nginx-rtmp-module的官方github地址:

GitHub - arut/nginx-rtmp-module: NGINX-based Media Streaming Server

使用命令:

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

解压:

unzip nginx-rtmp-module-master.zip
mv -i nginx-rtmp-module-master nginx-rtmp-module

4、编译安装:

./configure --add-module=../nginx-rtmp-module
make && make install

5、修改nginx的配置文件

vi /usr/local/nginx/conf/nginx.conf

加入以下内容:

rtmp{
	server{
		listen 1935;
		chunk_size 4000;
		application hls {
			live on;
			hls on;
			hls_path /home/rtmp/hls;
			hls_fragment 2s;
			hls_playlist_length 6s;
		}
	}
}

hls_path需要可读可写的权限。

修改http中的server模块:

server {  
    listen       80;  
    server_name  localhost; 

    location /hls {
	autoindex on;
	autoindex_exact_size off;
	autoindex_localtime on;
  	types {
		application/vnd.apple.mpegusr m3u8;
		video/mp2t ts;
	}
	root /home/rtmp;
	add_header Cache-Control no-cache;
    }
  
    #charset koi8-r;  
  
    #access_log  logs/host.access.log  main;  
  
    location / {  
        root   /usr/share/nginx/html;  
        index  index.html index.htm;

	if ($request_filename ~* ^.*?\.(txt|doc|pdf|tar|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
	add_header Content-Disposition: 'attachment;';
	}

	autoindex  on;#打开目录浏览功能
	autoindex_exact_size  off;#改为off后,显示出文件的大概大小,单位是kB或者MB或者GB
	autoindex_localtime on;#显示的文件时间为文件的服务器时间
    }  
  
    #error_page  404              /404.html;  
  
    # redirect server error pages to the static page /50x.html  
    #  
    error_page   500 502 503 504  /50x.html;  
    location = /50x.html {  
        root   html;  
    } 
}

6、测试nginx-rtmp服务

推流:

ffmpeg -re -i "264_aac.mp4" -vcodec libx264 -s 480x270 -vprofile baseline -acodec copy -f flv rtmp://192.168.1.190:1935/hls/test

  拉流: 

rtmp:/192.168.1.190:1935/hls/test
http://192.168.1.190:80/hls/test.m3u8 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值