nginx updates

This commit is contained in:
STAM 2020-08-04 16:02:37 +03:00
parent aaa7ef7b20
commit 8ac58973be
14 changed files with 582 additions and 0 deletions

View File

@ -168,6 +168,12 @@ matrix:
- docker build --compress -t epicmorg/balancer:php balancer/php
- docker push epicmorg/balancer:php
- name: NGinx + RTMP-HLS
script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker build --compress -t epicmorg/balancer:rtmp-hls balancer/rtmp-hls
- docker push epicmorg/balancer:rtmp-hls
- name: Apache (latest)
script:

View File

@ -1,4 +1,7 @@
## Changelog
* `August`
* added `testrail` based on `websites:php7.2` image. always `latest` version
* added `balancer:rtmp-hls` image, based on `balancer:latest` and [TareqAlqutami/rtmp-hls-server](https://github.com/TareqAlqutami/rtmp-hls-server) configs. `TareqAlqutami`, thank you for it.
* `May-july 2020`
* Upgraded `TeamCity Agnet`
* upgraded `nginx`

View File

@ -0,0 +1,41 @@
##### Building the final image #####
FROM epicmorg/balancer
ARG NGINX_RTMP_MODULE_VERSION=1.2.1
# Install dependencies
RUN apt-get update && \
apt-get install -y \
tree ca-certificates openssl libpcre3-dev \
librtmp1 libtheora0 libvorbis-dev libmp3lame0 \
libx264-dev libx265-dev && \
wget http://ftp.br.debian.org/debian/pool/main/libv/libvpx/libvpx4_1.6.1-3+deb9u2_amd64.deb && \
dpkg -i libvpx4_1.6.1-3+deb9u2_amd64.deb && \
rm -rfv libvpx4_1.6.1-3+deb9u2_amd64.de && \
rm -rfv /var/lib/apt/lists/*
RUN mkdir -p /usr/share/nginx/html /mnt/hls /mnt/dash /tmp/build && \
cd /tmp/build && \
wget https://github.com/arut/nginx-rtmp-module/archive/v${NGINX_RTMP_MODULE_VERSION}.tar.gz && \
tar -zxf v${NGINX_RTMP_MODULE_VERSION}.tar.gz && \
rm v${NGINX_RTMP_MODULE_VERSION}.tar.gz && \
cp /tmp/build/nginx-rtmp-module-${NGINX_RTMP_MODULE_VERSION}/stat.xsl /usr/share/nginx/html/stat.xsl && \
rm -rf /tmp/build
# Forward logs to Docker
RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
# Copy nginx config file to container
RUN rm -rfv /etc/nginx/nginx.conf
COPY conf/nginx.conf /etc/nginx/nginx.conf
# Copy html players to container
COPY players /usr/share/nginx/html/players
EXPOSE 1935
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]

21
balancer/rtmp-hls/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Tareq Alqutami
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,5 @@
all: nginx
nginx:
docker build --compress -t epicmorg/balancer:rtmp-hls .
docker push epicmorg/balancer:rtmp-hls

View File

@ -0,0 +1,99 @@
# RTMP-HLS Docker
** BASED ON https://github.com/TareqAlqutami/rtmp-hls-server **
**Docker image for video streaming server that supports RTMP, HLS, and DASH streams.**
[![Docker Automated build](https://img.shields.io/docker/cloud/automated/alqutami/rtmp-hls.svg)](https://hub.docker.com/r/alqutami/rtmp-hls/builds/)
[![Build Status](https://img.shields.io/docker/cloud/build/alqutami/rtmp-hls.svg)](https://hub.docker.com/r/alqutami/rtmp-hls)
## Description
This Docker image can be used to create a video streaming server that supports [**RTMP**](https://en.wikipedia.org/wiki/Real-Time_Messaging_Protocol), [**HLS**](https://en.wikipedia.org/wiki/HTTP_Live_Streaming), [**DASH**](https://en.wikipedia.org/wiki/Dynamic_Adaptive_Streaming_over_HTTP) out of the box.
It also allows adaptive streaming and custom transcoding of video streams.
All modules are built from source on Debian and Alpine Linux base images.
## Features
* The backend is [**Nginx**](http://nginx.org/en/) with [**nginx-rtmp-module**](https://github.com/arut/nginx-rtmp-module).
* [**FFmpeg**](https://www.ffmpeg.org/) for transcoding and adaptive streaming.
* Default settings:
* RTMP is ON
* HLS is ON (adaptive, 5 variants)
* DASH is ON
* Other Nginx configuration files are also provided to allow for RTMP-only streams or no-FFmpeg transcoding.
* Statistic page of RTMP streams at `http://<server ip>:<server port>/stats`.
* Available web video players (based on [video.js](https://videojs.com/) and [hls.js](https://github.com/video-dev/hls.js/)) at `/usr/local/nginx/html/players`.
Current Image is built using:
* Nginx 1.17.5 (compiled from source)
* Nginx-rtmp-module 1.2.1 (compiled from source)
* FFmpeg 4.2.1 (compiled from source)
This image was inspired by similar docker images from [tiangolo](https://hub.docker.com/r/tiangolo/nginx-rtmp/) and [alfg](https://hub.docker.com/r/alfg/nginx-rtmp/). It has small build size, adds support for HTTP-based streams and adaptive streaming using FFmpeg.
## Usage
### To run the server
```
docker run -d -p 1935:1935 -p 8080:8080 alqutami/rtmp-hls
```
For Alpine-based Image use:
```
docker run -d -p 1935:1935 -p 8080:8080 alqutami/rtmp-hls:latest-alpine
```
To run with custom conf file:
```
docker run -d -p 1935:1935 -p 8080:8080 -v custom.conf:/etc/nginx/nginx.conf alqutami/rtmp-hls
```
where `custom.conf` is the new conf file for Nginx.
### To stream to the server
* **Stream live RTMP content to:**
```
rtmp://<server ip>:1935/live/<stream_key>
```
where `<stream_key>` is any stream key you specify.
* **Configure [OBS](https://obsproject.com/) to stream content:** <br />
Go to Settings > Stream, choose the following settings:
* Service: Custom Streaming Server.
* Server: `rtmp://<server ip>:1935/live`.
* Stream key: anything you want, however provided video players assume stream key is `test`
### To view the stream
* **Using [VLC](https://www.videolan.org/vlc/index.html):**
* Go to Media > Open Network Stream.
* Enter the streaming URL: `rtmp://<server ip>:1935/live/<stream-key>`
Replace `<server ip>` with the IP of where the server is running, and
`<stream-key>` with the stream key you used when setting up the stream.
* For HLS and DASH, the URLs are of the forms:
`http://<server ip>:8080/hls/<stream-key>.m3u8` and
`http://<server ip>:8080/dash/<stream-key>_src.mpd` respectively.
* Click Play.
* **Using provided web players:** <br/>
The provided demo players assume the stream-key is called `test` and the player is opened in localhost.
* To play RTMP content (requires Flash): `http://localhost:8080/players/rtmp.html`
* To play HLS content: `http://localhost:8080/players/hls.html`
* To play HLS content using hls.js library: `http://localhost:8080/players/hls_hlsjs.html`
* To play DASH content: `http://localhost:8080/players/dash.html`
* To play RTMP and HLS contents on the same page: `http://localhost:8080/players/rtmp_hls.html`
**Notes:**
* These web players are hardcoded to play stream key "test" at localhost.
* To change the stream source for these players. Download the html files and modify the `src` attribute in the video tag in the html file. You can then mount the modified files to the container as follows:
```
docker run -d -p 1935:1935 -p 8080:8080 -v custom_players:/usr/local/nginx/html/players alqutami/rtmp-hls
```
where `custom_players` is the directory holding the modified html files.
## Copyright
Released under MIT license.
## More info
* **GitHub repo**: <https://github.com/TareqAlqutami/rtmp-hls-server.git>
* **Docker Hub image**: <https://hub.docker.com/r/alqutami/rtmp-hls>

View File

@ -0,0 +1,133 @@
load_module "/usr/lib/nginx/modules/ngx_rtmp_module.so";
worker_processes auto;
#error_log logs/error.log;
events {
worker_connections 1024;
}
# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
# ping 30s;
# notify_method get;
# This application is to accept incoming stream
application live {
live on; # Allows live input
# for each received stream, transcode for adaptive streaming
# This single ffmpeg command takes the input and transforms
# the source into 4 different streams with different bitrates
# and qualities. # these settings respect the aspect ratio.
exec_push /usr/bin/ffmpeg -i rtmp://localhost:1935/$app/$name -async 1 -vsync -1
-c:v libx264 -c:a aac -b:v 256k -b:a 64k -vf "scale=480:trunc(ow/a/2)*2" -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_low
-c:v libx264 -c:a aac -b:v 768k -b:a 128k -vf "scale=720:trunc(ow/a/2)*2" -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_mid
-c:v libx264 -c:a aac -b:v 1024k -b:a 128k -vf "scale=960:trunc(ow/a/2)*2" -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_high
-c:v libx264 -c:a aac -b:v 1920k -b:a 128k -vf "scale=1280:trunc(ow/a/2)*2" -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_hd720
-c copy -f flv rtmp://localhost:1935/show/$name_src;
}
# This is the HLS application
application show {
live on; # Allows live input from above application
deny play all; # disable consuming the stream from nginx as rtmp
hls on; # Enable HTTP Live Streaming
hls_fragment 3;
hls_playlist_length 20;
hls_path /mnt/hls/; # hls fragments path
# Instruct clients to adjust resolution according to bandwidth
hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
hls_variant _hd720 BANDWIDTH=2048000; # High bitrate, HD 720p resolution
hls_variant _high BANDWIDTH=1152000; # High bitrate, higher-than-SD resolution
hls_variant _mid BANDWIDTH=448000; # Medium bitrate, SD resolution
hls_variant _low BANDWIDTH=288000; # Low bitrate, sub-SD resolution
# MPEG-DASH
dash on;
dash_path /mnt/dash/; # dash fragments path
dash_fragment 3;
dash_playlist_length 20;
}
}
}
http {
sendfile off;
tcp_nopush on;
directio 512;
# aio on;
# HTTP server required to serve the player and HLS fragments
server {
listen 8080;
# Serve HLS fragments
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt;
add_header Cache-Control no-cache; # Disable 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;
}
}
# Serve DASH fragments
location /dash {
types {
application/dash+xml mpd;
video/mp4 mp4;
}
root /mnt;
add_header Cache-Control no-cache; # Disable 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;
}
}
# This URL provides RTMP statistics in XML
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl; # Use stat.xsl stylesheet
}
location /stat.xsl {
# XML stylesheet to view RTMP stats.
root /usr/share/nginx/html;
}
}
}

View File

@ -0,0 +1,117 @@
load_module "/usr/lib/nginx/modules/ngx_rtmp_module.so";
worker_processes auto;
#error_log logs/error.log;
events {
worker_connections 1024;
}
# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
# ping 30s;
# notify_method get;
# This application is to accept incoming stream
application live {
live on; # Allows live input
push rtmp://localhost:1935/show;
}
# This is the HLS application
application show {
live on; # Allows live input from above application
deny play all; # disable consuming the stream from nginx as rtmp
hls on; # Enable HTTP Live Streaming
hls_fragment 3;
hls_playlist_length 10;
hls_path /mnt/hls/; # hls fragments path
# MPEG-DASH
dash on;
dash_path /mnt/dash/; # dash fragments path
dash_fragment 3;
dash_playlist_length 10;
}
}
}
http {
sendfile off;
tcp_nopush on;
directio 512;
# aio on;
# HTTP server required to serve the player and HLS fragments
server {
listen 8080;
# Serve HLS fragments
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt;
add_header Cache-Control no-cache; # Disable 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;
}
}
# Serve DASH fragments
location /dash {
types {
application/dash+xml mpd;
video/mp4 mp4;
}
root /mnt;
add_header Cache-Control no-cache; # Disable 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;
}
}
# This URL provides RTMP statistics in XML
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl; # Use stat.xsl stylesheet
}
location /stat.xsl {
# XML stylesheet to view RTMP stats.
root /usr/share/nginx/html;
}
}
}

View File

@ -0,0 +1,16 @@
load_module "/usr/lib/nginx/modules/ngx_rtmp_module.so";
worker_processes auto;
rtmp_auto_push on;
events {}
rtmp {
server {
listen 1935;
listen [::]:1935;
application live {
live on;
record off;
}
}
}

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DASH Live Streaming</title>
<link href="https://vjs.zencdn.net/7.5.5/video-js.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/7.5.5/video.js"></script>
</head>
<body>
<h1>DASH Player</h1>
<video id="player" class="video-js vjs-default-skin" width="720" controls preload="auto">
<source src="/dash/test_src.mpd" type="application/dash+xml" />
</video>
<script>
var player = videojs('#player');
</script>
<div id="footer">
<font size="2"> Tareq-Alqutami - 2019</font>
</div>
</body>
</html>

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HLS Live Streaming</title>
<link href="https://vjs.zencdn.net/7.5.5/video-js.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/7.5.5/video.js"></script>
</head>
<body>
<h1>HLS Player</h1>
<video id="player" class="video-js vjs-default-skin" width="720" controls preload="auto">
<source src="/hls/test.m3u8" type="application/x-mpegURL" />
</video>
<script>
var player = videojs('#player');
</script>
<div id="footer">
<font size="2"> Tareq-Alqutami - 2019</font>
</div>
</body>
</html>

View File

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HLS streaming</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
</head>
<body>
<h1>HLS Player (using hls.js)</h1>
<div class="well">
<div class="embed-responsive embed-responsive-16by9">
<video id="video" style="max-height: 50%" class="embed-responsive-item video-js vjs-default-skin" controls muted="muted"></video>
</div>
</div>
<script>
if(Hls.isSupported()) {
var video = document.getElementById('video');
var hls = new Hls();
hls.loadSource('/hls/test.m3u8');
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED,function() {
video.play();
});
}
</script>
<div id="footer">
<font size="2">Tareq-Alqutami - 2019</font>
</div>
</body>
</html>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RTMP Live Streaming</title>
<title>Live Streaming</title>
<link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
<script src="https://unpkg.com/video.js/dist/video.js"></script>
<script src="https://unpkg.com/videojs-flash/dist/videojs-flash.min.js"></script>
<script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
</head>
<body>
<h1>RTMP Player</h1>
<video id="my_video_1" class="video-js vjs-default-skin" controls preload="auto" width="720"
data-setup='{"techOrder": ["html5","flash"]}'>
<source src="rtmp://127.0.0.1:1935/live/test" type="rtmp/mp4">
</video>
<div id="footer">
<font size="2">Tareq Alqutami - 2019</font>
</div>
</body>
</html>

View File

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Live Streaming</title>
<link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
<script src="https://unpkg.com/video.js/dist/video.js"></script>
<script src="https://unpkg.com/videojs-flash/dist/videojs-flash.min.js"></script>
<script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
</head>
<body>
<h1>RTMP Player</h1>
<video id="rtmp_video" class="video-js vjs-default-skin" controls preload="auto" width="720"
data-setup='{"techOrder": ["html5","flash"]}'>
<source src="rtmp://127.0.0.1:1935/live/test" type="rtmp/mp4">
</video>
<h1>HLS Player</h1>
<video id="hls_video" class="video-js vjs-default-skin" controls preload="auto" width="720"
data-setup='{"techOrder": ["html5","flash"]}'>
<source src="http://127.0.0.1:8080/hls/test.m3u8" type="application/x-mpegURL">
</video>
<div id="footer">
<font size="2">Tareq Alqutami - 2019</font>
</div>
</body>
</html>