-
Notifications
You must be signed in to change notification settings - Fork 42
/
README.md
144 lines (125 loc) · 6.75 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
## :whale:[docker-nginx-rtmp-ffmpeg](https://hub.docker.com/repository/docker/ar414/nginx-rtmp-ffmpeg)
[简体中文](./CN-README.md)
### Support
[![jetbrains](./assets/images/jetbrains.svg)](https://www.jetbrains.com/?from=nginx-rtmp-ffmpeg)
Based on the configuration and deployment of [docker-nginx-rtmp](https://github.com/alfg/docker-nginx-rtmp)the meaning of this article is to realize live streaming and live screen watermarking.
* Nginx 1.16.1(Stable version compiled from source code)
* nginx-rtmp-module 1.2.1(Compile from source)
* ffmpeg 4.2.1(Compile from source)
* Configured [nginx.conf](https://github.com/ar414-com/nginx-rtmp-ffmpeg-conf/blob/master/nginx.conf)
* Only support 1920*1080 (if you need to support other resolutions, please refer to [nginx.conf](https://github.com/alfg/docker-nginx-rtmp/blob/master/nginx.conf))
* Realize two-way shunt
* localhost
* Live cloud provider(例:AWS)
* Realize live watermark effect
* Watermark image storage location (in the container):/opt/images/logo.png
## :computer:Deploy and run
### Server
* Install docker (Centos7, other systems please use your search function)
```bash
$ yum -y install docker #install docker
$ systemctl enable docker #Configure startup
$ systemctl start docker #Start the docker service
```
* Pull the docker image and run
```bash
$ docker pull ar414/nginx-rtmp-ffmpeg
$ docker run -it -d -p 1935:1935 -p 8080:80 --rm ar414/nginx-rtmp-ffmpeg
```
* Push stream address(Stream live content to):
```
rtmp://<server ip>:1935/stream/$STREAM_NAME
```
* SSL certificate
Copy the certificate to the container, and modify the nginx.conf configuration file in the container, and then re-commit (all the files in the container need to be re-committed to take effect)
```
#/etc/nginx/nginx.conf
listen 443 ssl;
ssl_certificate /opt/certs/example.com.crt;
ssl_certificate_key /opt/certs/example.com.key;
```
### OBS configuration
* Stream Type: `Custom Streaming Server`
* URL: `rtmp://<server ip>:1935/stream`
* Stream Key:ar414
![obs-config](https://cdn.ar414.com/obs-config.png)
### Watch test
> HLS playback test tool:http://player.alicdn.com/aliplayer/setting/setting.html (If a certificate is configured, use https)
* HLS playback address
* With watermark:http://\<server ip>:8080/hls/ar414_wm.m3u8
![ar414-hls-wm](https://cdn.ar414.com/ar414-hls-wm.png)
* No watermark:http://\<server ip>:8080/hls/ar414.m3u8
![ar414-hls](https://cdn.ar414.com/ar414-hls.png)
> RTMP test tool:[PotPlayer](https://daumpotplayer.com/download/)
* RTMP playback address
* No watermark:rtmp://\<server ip>:1935/stream/ar414
![ar414-rtmp](https://cdn.ar414.com/ar414-rtmp.png)
* With watermark:Need to be diverted to other servers
## :page_facing_up:Brief explanation of configuration file (diversion, watermark and watermark position)
> [Full configuration file](https://github.com/ar414-com/nginx-rtmp-ffmpeg-conf/blob/master/nginx.conf)
* RTMP configuration
```bash
rtmp {
server {
listen 1935; #port
chunk_size 4000;
#RTMP Live streaming configuration
application stream {
live on;
# Add watermark and diversion, this time it is convenient to test diversion directly to the current server hls
# Actual production is generally diverted to the live cloud(AWS)
# Just replace the address that needs to be diverted
# With 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;
}
}
}
```
* If you need to push multiple live clouds, copy multiple exec ffmpeg as follows:
```bash
application stream {
live on;
#Shunt to local 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;
#Diverted 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;
#Diverted to Alibaba 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;
}
```
* Watermark position
* Watermark position
| Watermark image location | overlay value |
| ---- | ---- |
| Upper left corner | 10:10 |
| Upper right corner | main_w-overlay_w-10:10 |
| Bottom left | 10:main_h-overlay_h-10 |
| Bottom right corner | main_w-overlay_w-10 : main_h-overlay_h-10 |
* overlay param
| param | description |
| ---- | ---- |
| 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 |
### Support Author
[![coffee](http://cdn.ar414.com/coffee.png)](https://www.buymeacoffee.com/ar414) [![wx](https://cdn.ar414.com/wecaht-logo.png)](https://cdn.ar414.com/wxpay_coffee.jpg)[![alipay](https://cdn.ar414.com/alipay-logo.png)](https://cdn.ar414.com/alipay_coffee.jpg)