直播平臺大致流程 實時傳輸協議有:RTMP、HLS、HDL(HTTP-FLV) 編譯環境 apt-get install build-essential nginx安裝 安裝pcre(目前最新8.44) ./configure make && make install pcre-config --v ...
直播平臺大致流程
實時傳輸協議有:RTMP、HLS、HDL(HTTP-FLV)
編譯環境
apt-get install build-essential
nginx安裝
安裝pcre(目前最新8.44)
./configure make && make install pcre-config --version //查看版本
下載nginx-rtmp-module
源
git 下載https://github.com/arut/nginx-rtmp-module
安裝nginx(目前最新1.17.9)
./configure --add-module=../nginx-rtmp-module --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.44 make make install
obs studio視頻直播錄製軟體安裝(debian儘量9以上,因為ops有要求,不然自己編譯有點麻煩)
https://obsproject.com/download
ffmpeg轉碼安裝
https://obsproject.com/wiki/install-instructions#linux里有安裝流程
或者低版本的
sh -c 'echo "deb http://www.deb-multimedia.org jessie main" >> /etc/apt/sources.list' apt-get update apt-get install deb-multimedia-keyring apt-get install ffmpeg
rtmp參數配置
nginx.conf點播配置
#播放地址示例: rtmp://localhost/live/qq.mp4 rtmp { #RTMP服務 server { listen 1935; #//服務埠 chunk_size 4096; #//數據傳輸塊的大小 application live { play /usr/local/nginx/video; #//視頻文件存放位置。 } } }
nginx.conf直播配置
rtmp里
application show { live on; #enable HLS hls on; hls_path /usr/local/nginx/video/hls; hls_fragment 3; hls_playlist_length 20; }
http-server里
location /hls { # Disable cache add_header Cache-Control no-cache; # CORS setup add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Expose-Headers' 'Content-Length'; # allow CORS preflight requests if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Content-Length' 0; return 204; } types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /usr/local/nginx/video/hls/; add_header Cache-Control no-cache; }
重啟nginx
sudo ./sbin/nginx -s reload
開啟 ffmpeg
ffmpeg -re -i /usr/local/nginx/video/test.mp4 -vcodec libx264 -vprofile baseline -acodec aac -strict -2 -f flv rtmp://localhost/show/stream
結果