Skip to content

Commit

Permalink
Added envsubst for environment variable substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioassuncao committed Sep 27, 2021
1 parent bb0de4c commit db0e9a8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ LABEL MAINTAINER Fábio Assunção <[email protected]>

ENV FILESYSTEM 'local'
ENV STORAGE_PATH '/opt/data'
ENV HTTP_PORT 80
ENV HTTPS_PORT 443
ENV RTMP_PORT 1935

RUN apk add --update \
bash \
Expand All @@ -153,7 +156,7 @@ COPY --from=build-ffmpeg /usr/local /usr/local
COPY --from=build-ffmpeg /usr/lib/libfdk-aac.so.2 /usr/lib/libfdk-aac.so.2

ENV PATH "${PATH}:/usr/local/nginx/sbin"
ADD nginx.conf /etc/nginx/nginx.conf
ADD nginx.conf /etc/nginx/nginx.conf.template
RUN mkdir -p /opt/data && mkdir /www
ADD static /www/static

Expand Down
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ rtmp://<server ip>:1935/stream/$STREAM_NAME
* URL: `rtmp://localhost:1935/stream`
* Example Stream Key: `hello`

## Using AWS and CloudFront

### Watch Stream
### Watch Stream using AWS and CloudFront

Access by using your S3 public URL.

Expand All @@ -53,30 +51,30 @@ or you can set your cloudfront (cache disabled) distribution then based on your

> Don't forget to set public access and enable CORS in your s3 bucket
### Watch Stream using Local Storage
* Load up the example hls.js player in your browser:
```
http://localhost:8080/player.html?url=http://localhost:8080/live/hello.m3u8
```

* Or in Safari, VLC or any HLS player, open:
```
http://localhost:8080/live/$STREAM_NAME.m3u8
```
* Example Playlist: `http://localhost:8080/live/hello.m3u8`
* [HLS.js Player](https://hls-js.netlify.app/demo/?src=http%3A%2F%2Flocalhost%3A8080%2Flive%2Fhello.m3u8)
* FFplay: `ffplay -fflags nobuffer rtmp://localhost:1935/stream/hello`

## Using your Own Server

### SSL (optional)
### SSL
To enable SSL, see [nginx.conf](nginx.conf) and uncomment the lines:
```
listen 443 ssl;
ssl_certificate /opt/certs/example.com.crt;
ssl_certificate_key /opt/certs/example.com.key;
```

This will enable HTTPS using a self-signed certificate supplied in [/certs](/certs). If you wish to use HTTPS, it is **highly recommended** to obtain your own certificates and update the `ssl_certificate` and `ssl_certificate_key` paths.

I recommend using [Certbot](https://certbot.eff.org/docs/install.html) from [Let's Encrypt](https://letsencrypt.org).


### Watch Stream
* In Safari, VLC or any HLS player, open:
```
http://<server ip>:8080/live/$STREAM_NAME.m3u8
```
* Example Playlist: `http://localhost:8080/live/hello.m3u8`
* [VideoJS Player](https://video-dev.github.io/hls.js/stable/demo/?src=http%3A%2F%2Flocalhost%3A8080%2Flive%2Fhello.m3u8)
* FFplay: `ffplay -fflags nobuffer rtmp://localhost:1935/stream/hello`
> This will enable HTTPS using a self-signed certificate supplied in [/certs](/certs). If you wish to use HTTPS, it is highly recommended to obtain your own certificates and update the `ssl_certificate` and `ssl_certificate_key` paths.
## Credits
* https://github.com/alfg/docker-nginx-rtmp
Expand Down
4 changes: 3 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ if [ "$FILESYSTEM" = "s3" ] ; then
fi

# Run NGINX
nginx
envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < \
/etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && \
nginx
37 changes: 20 additions & 17 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ events {

rtmp {
server {
listen 1935;
listen ${RTMP_PORT};
chunk_size 4000;

application stream {
live on;

exec ffmpeg -i rtmp://localhost:1935/stream/$name
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_720p2628kbs
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 1000k -f flv -g 30 -r 30 -s 854x480 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_480p1128kbs
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 640x360 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_360p878kbs
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 400k -f flv -g 30 -r 30 -s 426x240 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_240p528kbs
-c:a libfdk_aac -b:a 64k -c:v libx264 -b:v 200k -f flv -g 15 -r 15 -s 426x240 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_240p264kbs;
exec ffmpeg -i rtmp://localhost:${RTMP_PORT}/stream/$name
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp://localhost:${RTMP_PORT}/hls/$name_720p2628kbs
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 1000k -f flv -g 30 -r 30 -s 854x480 -preset superfast -profile:v baseline rtmp://localhost:${RTMP_PORT}/hls/$name_480p1128kbs
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 640x360 -preset superfast -profile:v baseline rtmp://localhost:${RTMP_PORT}/hls/$name_360p878kbs
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 400k -f flv -g 30 -r 30 -s 426x240 -preset superfast -profile:v baseline rtmp://localhost:${RTMP_PORT}/hls/$name_240p528kbs
-c:a libfdk_aac -b:a 64k -c:v libx264 -b:v 200k -f flv -g 15 -r 15 -s 426x240 -preset superfast -profile:v baseline rtmp://localhost:${RTMP_PORT}/hls/$name_240p264kbs;
}

application hls {
Expand All @@ -28,7 +28,7 @@ rtmp {
hls_fragment_naming system;
hls_fragment 5;
hls_playlist_length 10;
hls_path /opt/data/hls;
hls_path ${STORAGE_PATH}/hls;
hls_nested on;

hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=1280x720;
Expand All @@ -41,6 +41,9 @@ rtmp {
}

http {
root /www/static;
sendfile off;
tcp_nopush on;
access_log /dev/stdout combined;

# Uncomment these lines to enable SSL.
Expand All @@ -50,11 +53,12 @@ http {
# ssl_session_timeout 10m;

server {
listen 80;
listen ${HTTP_PORT};

# Uncomment these lines to enable SSL.
# Update the ssl paths with your own certificate and private key.
# listen 443 ssl;

# listen ${HTTPS_PORT} ssl;
# ssl_certificate /opt/certs/example.com.crt;
# ssl_certificate_key /opt/certs/example.com.key;

Expand All @@ -63,13 +67,13 @@ http {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /opt/data;
root ${STORAGE_PATH};
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}

location /live {
alias /opt/data/hls;
alias ${STORAGE_PATH}/hls;
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
Expand All @@ -80,15 +84,14 @@ http {

location /stat {
rtmp_stat all;
rtmp_stat_stylesheet static/stat.xsl;
rtmp_stat_stylesheet stat.xsl;
}

location /static {
alias /www/static;
location /stat.xsl {
root /www/static;
}

location = /crossdomain.xml {
root /www/static;
location /crossdomain.xml {
default_type text/xml;
expires 24h;
}
Expand Down

0 comments on commit db0e9a8

Please sign in to comment.