RTMP Server + s3 (Cloudfront) + NGINX + OBS live streaming
1.3K
Dockerfile linksNote: Note: There are tags for each build date. If you need to "pin" the Docker image version you use, you can select one of those tags. E.g. marshallchabanga/nginx-rtmp-s3fs:latest-08-01-2024.
Docker image with Nginx using the nginx-rtmp-module module for live multimedia (video) streaming.
This Docker image can be used to create an RTMP server for multimedia / video streaming using Nginx, nginx-rtmp-module and s3fs, built from the current latest sources (Nginx 1.15.0, nginx-rtmp-module 1.2.1 and s3fs v1.85).
This was inspired by other similar previous images from tiangolo, dvdgiessen, jasonrivers, aevumdecessus and by an OBS Studio post.
The main purpose (and test case) to build it was to allow streaming from OBS Studio to different clients at the same time. Mount s3 bucket to store streaming media
Streaming using AWS CloudFront and s3 integration
Backup recordings into s3 bucket
GitHub repo: https://github.com/marshallchabanga/nginx-rtmp-docker
Docker Hub image: https://hub.docker.com/r/marshallchabanga/nginx-rtmp-s3fs/
docker-compose.yml and add the content below into it. Run docker-compose build and then docker-compose upversion: "3.9"
services:
rtmp:
image: marshallchabanga/nginx-rtmp-s3fs
ports:
- "1935:1935"
- "9080:9080"
container_name: rtmp_server
devices:
- /dev/fuse
cap_add:
- SYS_ADMIN
security_opt:
- apparmor:unconfined
environment:
AWS_ACCESS_KEY_ID: dfdgdfdg
AWS_SECRET_ACCESS_KEY: fgdgdg
AWS_S3_BUCKET_NAME: bisky-bucket
AWS_S3_REGION: ap-northeast-2
Run a container with the command above
Open OBS Studio
Click the "Settings" button
Go to the "Stream" section
In "Stream Type" select "Custom Streaming Server"
In the "URL" enter the rtmp://<ip_of_host>/live replacing <ip_of_host> with the IP of the host in which the container is running. For example: rtmp://localhost:1935/live
In the "Stream key" use a "key" that will be used later in the client URL to display that specific stream. For example: test
Click the "OK" button
In the section "Sources" click the "Add" button (+) and select a source (for example "Screen Capture") and configure it as you need
Click the "Start Streaming" button
Access by using your S3 public URL.
For example => https://your-s3-bucket.s3.region.amazonaws.com/test.m3u8
or you can set your cloudfront (cache disabled) distribution then based on your S3
ATTENTION: Don't forget to set public access and enable CORS in your s3 bucket. Choose us-east-1 region for now when creating a bucket
ENABLE CORS EXAMPLE
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"HEAD"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 3000
}
]
If something is not working you can check the logs of the container with:
docker logs nginx-rtmp-s3fs
If you need to modify the configurations you can create a file nginx.conf and replace the one in this image using a Dockerfile that is based on the image, for example:
FROM marshallchabanga/nginx-rtmp-s3fs
COPY nginx.conf /etc/nginx/nginx.conf
The current nginx.conf contains:
worker_processes auto;
rtmp_auto_push on;
events {}
rtmp {
server {
listen 1935; # Listen on standard RTMP port
application live {
live on;
hls on;
hls_path /var/tmp/hls;
hls_fragment 10s; # default is 5s
hls_playlist_length 5m; # default is 30s
# once playlist length is reached it deletes the oldest fragments
}
}
}
http {
server {
listen 9080;
location / {
root /www;
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
application/octet-stream ts;
}
root /var/tmp;
add_header Cache-Control no-cache;
# To avoid issues with cross-domain HTTP requests (e.g. during development)
add_header Access-Control-Allow-Origin *;
}
}
}
You can start from it and modify it as you need. Here's the documentation related to nginx-rtmp-module.
Clone the spring-boot example, you can modify Dockerfile, index.html and nginx.conf in rtmp folder
This image is built from the same base official images that most of the other official images, as Python, Node, Postgres, Nginx itself, etc. Specifically, buildpack-deps which is in turn based on debian. So, if you have any other image locally you probably have the base image layers already downloaded.
It is built from the official sources of Nginx and nginx-rtmp-module without adding anything else. (Surprisingly, most of the available images that include nginx-rtmp-module are made from different sources, old versions or add several other components).
It has a simple default configuration that should allow you to send one or more streams to it and have several clients receiving multiple copies of those streams simultaneously. (It includes rtmp_auto_push and an automatic number of worker processes).
--with-debug compile option. PR #16 by @agconti.This project is licensed under the terms of the MIT License.
Content type
Image
Digest
sha256:bbd69bb79…
Size
101.4 MB
Last updated
almost 3 years ago
docker pull marshallchabanga/nginx-rtmp-s3fs