1. 准備環境
- 安裝操作系統Cenos
- 配置yum源
yum:https://developer.aliyun.com/mirror/- Nginx依賴
gcc-c++ zlib pcre openssl openssl-devel- Nginx和擴展模塊
Nginx本身只是一個服務器,對流媒體並沒有支持,所以我們要下載對應的模塊來擴展其功能
MP4模塊:http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
FLV模塊:http://sourceforge.net/projects/yamdi/files/yamdi/yamdi-1.9.tar.gz
直播流模塊:https://github.com/adwpc/nginx-rtmp-module
FastDFS模塊:https://github.com/happyfish100/fastdfs-nginx-module- FFMPEG
ffmpeg :https://ffmpeg.zeranoe.com/builds/- OBS推流
- EV拉流
2. 安裝環境
2.1 上傳所有模塊到系統中
mkdir /opt/nginx
cd /opt/nginx
rz nginx-1.8.1.tar.gz
rz nginx_mod_h264_streaming-2.2.7.tar.gz
rz yamdi-1.9.tar.gz
rz nginx-rtmp-module-master.zip
2.2 安裝FLV模塊
tar -zxvf yamdi-1.9.tar.gz
cd yamdi
./configure
mark && make install
2.3 解壓MP4模塊
tar -zxvf nginx_mod_h264_streaming-2.2.7.tar.gz
處理一個bug
cd /opt/nginx/nginx_mod_h264_streaming/src
注釋157行-161行
/* TODO: Win32 */
// if (r->zero_in_uri)
// {
// return NGX_DECLINED;
// }
2.4 解壓nginx
tar -zxvf nginx-1.8.1.tar.gz
tar -zxvf nginx_mod_h264_streaming.tar.gz
unzip nginx-rtmp-module-master.zip
2.5 安裝nginx並添加模塊
./configure --add-module=../nginx_mod_h264_streaming --add-module=../nginx-rtmp-module-master --with-http_ssl_module --prefix=/opt/software/nginx --with-http_flv_module --with-http_stub_status_module
注:如果編譯報錯, vim objs/Makefile (修改objs/Makefile文件, 去掉其中的"-Werror"), 然后就能夠正常編譯了.
2.6 播放配置
cd /opt/software/nginx/conf
vim nginx.conf
添加對FLV和MP4的支持
location ~ \.flv {
flv;
}
location ~ \.mp4$ {
mp4;
}
2.7 FFmpeg
FFmpeg是一套可以用來記錄、轉換數字音頻、視頻,並能將其轉化為流的開源計算機程序
上傳
rz ffmpeg-4.2.2.tar.bz2
安裝
yum install bzip2 #因為后綴是bz2的 要安裝 bzip2
tar -jxvf ffmpeg-4.2.2.tar.bz2 #使用 -jxvf 解壓bz2文件
cd ffmpeg-4.2.2 #進入目錄
./configure --prefix=/opt/software/ffmpeg #配置 設置安裝路徑
make && make install #安裝
3. 點播
上傳測試MP4
cd /opt/software/nginx/html
rz test.mp4
查看 http://192.168.3.9/test.mp4
4. 直播
4.1 配置服務
cd /opt/software/nginx/conf
vim nginx.conf
rtmp {
server {
listen 1935; #監聽的端口
chunk_size 4096;
application hls { #rtmp推流請求路徑
live on;
hls on;
hls_path /opt/software/nginx/html/hls;
hls_fragment 5s;
}
}
}
mkdir /opt/software/nginx/html/hls
4.2 直播推流
推流指的是把采集階段封包好的內容傳輸到服務器的過程。其實就是將現場的視頻信號傳到網絡的過程
設置場景
場景增加視頻捕獲設備,顯示器捕獲或窗口捕獲
注:窗口黑屏解決方案
設備管理器中-->顯示適配器-->獨立顯卡-禁用
設置推流地址
rtmp服務器:rtmp://192.168.3.9:1935/hls/
密鑰:12345
4.3 直播拉流
拉流是指服務器已有直播內容,用指定地址進行拉取的過程
借用EV播放
輸入拉流地址
rtmp地址:rtmp://192.168.3.9:1935/hls/12345
點擊開始觀看直播