最近幫朋友的公司部署了一套分流+水印的直播系統 nginx
順手打包成docker鏡像,方便你們須要用到的時候開箱即用,不須要百度一些零碎的文章 也可作簡單的直播服務,只需調整配置文件即可達到你的需求.git
需求:將直播流分流到兩個雲廠商的直播雲,一個有水印,一個無水印。使用hls播放github
朋友需求的拓撲示意圖:docker
當前拓撲示意圖(阿某雲和騰訊雲不方便放出推流和拉流地址,有興趣的同窗能夠去申請玩一下)服務器
基於docker-nginx-rtmp進行配置部署,這篇文章的意義是實現直播分流及直播畫面水印.app
一、安裝docker工具
$ yum -y install docker #安裝docker $ systemctl enable docker #配置開機啓動 $ systemctl start docker #啓動docker服務
二、拉取docker鏡像並運行post
$ docker pull ar414/nginx-rtmp-ffmpeg $ docker run -it -d -p 1935:1935 -p 8080:80 --rm ar414/nginx-rtmp-ffmpeg
三、推流地址(Stream live content to):測試
rtmp://<server ip>:1935/stream/$STREAM_NAME
四、SSL證書 spa
將證書複製到容器內,並在容器內修改nginx.conf配置文件,而後從新commit(操做容器內的文件都須要從新commit纔會生效)
listen 443 ssl; ssl_certificate /opt/certs/example.com.crt; ssl_certificate_key /opt/certs/example.com.key;
Custom Streaming Server
rtmp://<server ip>:1935/stream
六、觀看測試
HLS播放測試工具:player.alicdn.com/aliplayer/s… (若是配置了證書則使用https)
七、HLS播放地址
RTMP測試工具:PotPlayer
八、RTMP播放地址
rtmp://<server ip>:1935/stream/ar414
須要分流到其餘服務器上
:page_facing_up:配置文件簡解(分流、水印及水印位置)
完整配置文件:
https://github.com/ar414-com/...
九、RTMP配置
rtmp { server { listen 1935; #端口 chunk_size 4000; #RTMP 直播流配置 application stream { live on; #添加水印及分流,此次方便測試直接分流到當前服務器hls #實際生產通常都分流到直播雲(騰訊雲、阿某雲、ucloud) #只需把須要分流的地址替換便可 #有水印:rtmp://localhost:1935/hls/$name_wm #無水印:rtmp://localhost:1935/hls/$name exec ffmpeg -i rtmp://localhost:1935/stream/$name -i /opt/images/ar414.png -filter_complex "overlay=10:10,split=1[ar414]" -map '[ar414]' -map 0:a -s 1920x1080 -c:v libx264 -c:a aac -g 30 -r 30 -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost:1935/hls/$name_wm -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1920x1080 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name; } application hls { live on; hls on; hls_fragment 5; hls_path /opt/data/hls; } } }
若是須要推多個直播雲則複製多個 exec ffmpeg便可 以下:
application stream { live on; #分流至本機hls exec ffmpeg -i rtmp://localhost:1935/stream/$name -i /opt/images/ar414.png -filter_complex "overlay=10:10,split=1[ar414]" -map '[ar414]' -map 0:a -s 1920x1080 -c:v libx264 -c:a aac -g 30 -r 30 -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost:1935/hls/$name_wm -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1920x1080 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name; #分流至騰訊雲 exec ffmpeg -i rtmp://localhost:1935/stream/$name -i /opt/images/ar414.png -filter_complex "overlay=10:10,split=1[ar414]" -map '[ar414]'-map 0:a -s 1920x1080 -c:v libx264 -c:a aac -g 30 -r 30 -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://live-push.tencent.com/stream/$name_wm -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1920x1080 -preset superfast -profile:v baseline rtmp://live-push.tencent.com/stream/$name; #分流至阿某雲 exec ffmpeg -i rtmp://localhost:1935/stream/$name -i /opt/images/ar414.png -filter_complex "overlay=10:10,split=1[ar414]" -map '[ar414]' -map 0:a -s 1920x1080 -c:v libx264 -c:a aac -g 30 -r 30 -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://live-push.aliyun.com/stream/$name_wm -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1920x1080 -preset superfast -profile:v baseline rtmp://live-push.aliyun.com/stream/$name; }
十一、水印位置
原文鏈接:
https://juejin.im/post/5e6ba6...