赞
踩
直播源码搭建教程5 分钟完成(直播 + 分流 + 画面水印)
- $ yum -y install docker #安装docker
- $ systemctl enable docker #配置开机启动
- $ systemctl start docker #启动docker服务
- 复制代码
- #如果速度慢可使用阿某云:docker pull registry.cn-shenzhen.aliyuncs.com/ar414/nginx-rtmp-ffmpeg:v1
- $ docker pull ar414/nginx-rtmp-ffmpeg
- $ docker run -it -d -p 1935:1935 -p 8080:80 --rm ar414/nginx-rtmp-ffmpeg
- 复制代码
- rtmp://<server ip>:1935/stream/$STREAM_NAME
- 复制代码
将证书复制到容器内,并在容器内修改nginx.conf配置文件,然后重新commit(操作容器内的文件都需要重新commit才会生效)
- #/etc/nginx/nginx.conf
- 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)
RTMP测试工具:PotPlayer
- 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;
- }
- }
- }
- 复制代码
- 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;
- }
- 复制代码
水印位置
水印图片位置 | overlay值 |
---|---|
左上角 | 10:10 |
右上角 | main_w-overlay_w-10:10 |
左下角 | 10:main_h-overlay_h-10 |
右下角 | main_w-overlay_w-10 : main_h-overlay_h-10 |
overlay参数
参数 | 说明 |
---|---|
main_w | 视频单帧图像宽度(当前配置文件1920) |
main_h | 视频单帧图像高度(当前配置文件1080) |
overlay_w | 水印图片的宽度 |
overlay_h | 水印图片的高度 |
直播源码搭建教程5 分钟完成(直播 + 分流 + 画面水印)本文转载自网络,感谢(AR414)的分享,转载仅为分享干货知识,如有侵权欢迎联系云豹科技进行删除处理
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。