preface
Ar414 recently deployed a streaming + watermarking live streaming system for a friend’s company
Conveniently packaged into docker image, convenient for everyone to use when out of the box, do not need baidu some fragmented articles can also do a simple live streaming service, just adjust the configuration file can meet your needs.
Requirement: Split live stream into two cloud vendors’ live clouds, one with watermark and one without. Use HLS to play
Topology diagram of friend needs:
Current topology diagram (a certain cloud and Tencent cloud is not convenient to release the push stream and pull stream address, interested students can apply to play)
docker-nginx-rtmp-ffmpeg
Based on the configuration and deployment of Docker-nginx-rtmp, the significance of this article is to achieve live streaming streaming and live image watermarking.
- Nginx 1.16.1 (stable version compiled from source)
- Nginx-rtmp-module 1.2.1 (compiled from source)
- Ffmpeg 4.2.1 (compiled from source)
- configurednginx.conf
- Only 1920*1080 is supported (see nginx.conf for other resolutions)
- Achieve two channels of shunting
- This machine
- Live streaming cloud (e.g. Ax Cloud, Tencent Cloud, UCloud)
- Achieve live watermark effect
- Save watermark image (in container) : /opt/images/logo.png
The deployment of running
The server
- Install Docker (Centos7, other systems please use your search function)
$ yum -y install docker # installation docker
$ systemctl enable docker Configure boot
$ systemctl start docker Start the Docker service
Copy the code
- Pull the Docker image and run it
O # slow if can use a cloud: 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
Copy the code
- Stream live content to:
rtmp://<server ip>:1935/stream/$STREAM_NAME
Copy the code
- SSL certificate
Copy the certificate to the container, modify the nginx.conf configuration file inside the container, and then recommit (all files in the container need to be recommitted)
#/etc/nginx/nginx.conf
listen 443 ssl;
ssl_certificate /opt/certs/example.com.crt;
ssl_certificate_key /opt/certs/example.com.key;
Copy the code
OBS configuration
- Stream Type:
Custom Streaming Server
- URL:
rtmp://<server ip>:1935/stream
- The Stream Key: ar414
Watch the test
HLS play testing tools: player.alicdn.com/aliplayer/s… (If a certificate is configured, use HTTPS.)
- HLS Broadcast address
- There is a watermark: http://
:8080/ HLS /ar414_wm.m3u8
- No watermark: http://
:8080/ HLS /ar414.m3u8
- There is a watermark: http://
RTMP test tool: PotPlayer
- RTMP Play address
- No watermark: RTMP ://
:1935/stream/ar414
- Watermarked: Need to stream to other servers
- No watermark: RTMP ://
: page_facing_UP: Simplified configuration file (shunt, watermark and watermark location)
Complete configuration file
- RTMP configuration
rtmp {
server {
listen 1935; # port
chunk_size 4000;
#RTMP live stream configuration
application stream {
live on;
# Add watermark and shunt, this time convenient test shunt directly to the current server HLS
# The actual production is generally transferred to live streaming cloud (Tencent Cloud, AHx Cloud, UCloud)
Replace the address that needs to be shunted
# have a watermark: RTMP: / / localhost: 1935 / HLS / $name_wm
# no watermark: 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; }}}Copy the code
- If you need to push multiple live clouds, copy multiple exec FFmpeg as follows:
application stream {
live on;
# Shunt to 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;
# Stream to Tencent cloud
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;
# Stream to a certain cloud
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;
}
Copy the code
- The watermark position
-
The watermark position
Location of watermark image Overlay value The upper left corner 10:10 The top right corner main_w-overlay_w-10:10 The lower left corner 10:main_h-overlay_h-10 The lower right corner main_w-overlay_w-10 : main_h-overlay_h-10 -
Overlay parameters
parameter instructions main_w Video single frame image width (current profile 1920) main_h Video single frame image height (current profile 1080) overlay_w The width of the watermark image overlay_h The height of the watermark image
-
conclusion
- Please give me a start if you think it is helpful to you