[root@localhost ~]# tar xvf nginx-1.8.1.tar.gz [root@localhost ~]# unzip nginx-rtmp-module-master.zip [root@localhost ~]# cd nginx-1.8.1 [root@localhost ~]# yum -y install zlib zlib-devel openssl* pcre pcre-devel gd-devel #nginx的依赖包 [root@localhost nginx-1.8.1]# ./configure --add-module=../nginx-rtmp-module-master [root@localhost nginx-1.8.1]# make -j 4 && make install
[root@localhost nginx-1.8.1]# cd /usr/local/nginx [root@localhost nginx ]# ./sbin/nginx #启动服务
在浏览器中输入虚拟机的IP或者localhost出现以下则说明编译安装成功html
[root@centos6(cyn) nginx ]# vim /usr/local/nginx/conf/nginx.conf#在配置文件最后加上这段rtmp的配置 rtmp { #rtmp配置的块,这个地方就是直播的配置的根 server { #服务器的实例 listen 1935;#监听而且接受的端口 application mytv { #应用/实例的三种类型(1)rtmp录播(vod),(2)rtmp直播(live),(3)hls直播(hls) live on; #开启直播直播模式,一对多广播 hls on; #开启直播 hls_path /usr/local/nginx/html/hls;#录制视频文件的目录/路径 hls_fragment 2s;#后面接时间,用来设置每个块的大小。默认是5秒。只能为整数 } } }
下面是一些hls的配置,可根据本身的需求来配置linux
hls_playlist_length: 设置播放列表的长度,单位是秒 hls_sync: 音视频的同步时间 hls_continuous: on|off 设置连续模式,是从中止播放的点开始仍是直接跳过 hls_nested: on|off 默认是off。打开后的做用是每条流本身有一个文件夹 hls_base_url: 设置基准URL,对于m3u8中使用相对URL有效 hls_cleanup: on|off 默认是开着的,是否删除列表中已经没有的媒体块 hls_fragment_naming: sequential(使用增加式的整数命名) | timestamp(使用媒体块的时间戳) | system(使用系统时间戳)命名方式 hls_fragment_naming_granularity: 若是使用时间戳命名时时间戳的精度 hls_fragment_slicing: plain(媒体块达到须要的duration就换)|aligned(当到达的数据库块时几个duration)
[root@localhost nginx]# mkdir /usr/local/nginx/html/hls
[root@localhost nginx]#./sbin/nginx -s stop [root@localhost nginx]#./sbin/nginx [root@localhost nginx]# iptables -F [root@localhost nginx]# setenforce 0