[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