Convert Figma logo to code with AI

alfg logodocker-nginx-rtmp

🐋 A Dockerfile for nginx-rtmp-module + FFmpeg from source with basic settings for streaming HLS. Built on Alpine Linux.

1,052
400
1,052
15

Top Related Projects

Docker image with Nginx using the nginx-rtmp-module module for live multimedia (video) streaming.

NGINX-based Media Streaming Server

25,280

SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.

Quick Overview

Docker-nginx-rtmp is a Dockerized NGINX server with RTMP module for live streaming. It provides a ready-to-use container for setting up a streaming server with minimal configuration, supporting various streaming protocols including RTMP, HLS, and DASH.

Pros

  • Easy setup and deployment using Docker
  • Supports multiple streaming protocols (RTMP, HLS, DASH)
  • Includes pre-configured NGINX with RTMP module
  • Customizable through environment variables and configuration files

Cons

  • Limited documentation for advanced configurations
  • May require additional setup for complex streaming scenarios
  • Potential performance overhead due to containerization
  • Lacks built-in authentication and security features

Getting Started

  1. Pull the Docker image:

    docker pull alfg/nginx-rtmp
    
  2. Run the container:

    docker run -it -p 1935:1935 -p 8080:80 --rm alfg/nginx-rtmp
    
  3. Stream to the server using RTMP:

    ffmpeg -re -i INPUT_FILE -c copy -f flv rtmp://localhost:1935/stream/STREAM_NAME
    
  4. Play the stream:

    • RTMP: rtmp://localhost:1935/stream/STREAM_NAME
    • HLS: http://localhost:8080/hls/STREAM_NAME.m3u8
    • DASH: http://localhost:8080/dash/STREAM_NAME.mpd
  5. (Optional) Mount a custom configuration:

    docker run -it -p 1935:1935 -p 8080:80 -v /path/to/nginx.conf:/opt/nginx/nginx.conf --rm alfg/nginx-rtmp
    

For more advanced usage and configuration options, refer to the project's GitHub repository and documentation.

Competitor Comparisons

Docker image with Nginx using the nginx-rtmp-module module for live multimedia (video) streaming.

Pros of nginx-rtmp-docker

  • More recent updates and active maintenance
  • Includes HLS (HTTP Live Streaming) support out of the box
  • Offers a simpler, more streamlined configuration

Cons of nginx-rtmp-docker

  • Less customization options compared to docker-nginx-rtmp
  • Fewer pre-configured features and modules
  • Limited documentation and usage examples

Code Comparison

nginx-rtmp-docker:

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            hls on;
            hls_path /tmp/hls;
        }
    }
}

docker-nginx-rtmp:

rtmp {
    server {
        listen 1935;
        chunk_size 4000;

        application live {
            live on;
            record off;
            allow publish all;
            allow play all;
        }
    }
}

The code comparison shows that nginx-rtmp-docker includes HLS configuration by default, while docker-nginx-rtmp focuses on basic RTMP settings. docker-nginx-rtmp provides more granular control over publish and play permissions, which may be beneficial for certain use cases.

Both repositories offer Docker-based NGINX RTMP servers, but they cater to slightly different needs. nginx-rtmp-docker is more suitable for users who want a simple setup with HLS support, while docker-nginx-rtmp provides more flexibility and customization options for advanced users.

NGINX-based Media Streaming Server

Pros of nginx-rtmp-module

  • More mature and widely used project with a larger community
  • Offers more advanced features and customization options
  • Can be integrated into existing Nginx installations

Cons of nginx-rtmp-module

  • Requires more setup and configuration compared to the Docker-based solution
  • May be more challenging for beginners to implement and manage
  • Lacks the out-of-the-box containerization benefits of docker-nginx-rtmp

Code Comparison

nginx-rtmp-module configuration example:

rtmp {
    server {
        listen 1935;
        application live {
            live on;
            record off;
        }
    }
}

docker-nginx-rtmp Dockerfile excerpt:

FROM alpine:3.14
RUN apk add --no-cache nginx nginx-mod-rtmp

EXPOSE 1935
CMD ["nginx", "-g", "daemon off;"]

The nginx-rtmp-module requires manual configuration within the Nginx setup, while docker-nginx-rtmp provides a pre-configured Docker image with RTMP support. The docker-nginx-rtmp approach simplifies deployment but may offer less flexibility for advanced configurations. nginx-rtmp-module allows for more granular control over the RTMP server settings but requires more expertise to set up and maintain.

25,280

SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.

Pros of SRS

  • More comprehensive streaming solution with support for multiple protocols (RTMP, HLS, WebRTC, etc.)
  • Better performance and scalability for large-scale deployments
  • Active development and community support

Cons of SRS

  • More complex setup and configuration compared to the simpler docker-nginx-rtmp
  • Steeper learning curve for beginners
  • Larger resource footprint due to additional features

Code Comparison

SRS configuration example:

listen              1935;
max_connections     1000;
srs_log_tank        file;
srs_log_file        ./objs/srs.log;
http_server {
    enabled         on;
    listen          8080;
}

docker-nginx-rtmp configuration example:

rtmp {
    server {
        listen 1935;
        chunk_size 4096;
        application live {
            live on;
            record off;
        }
    }
}

The SRS configuration offers more options and flexibility, while docker-nginx-rtmp provides a simpler setup for basic RTMP streaming. SRS includes additional features like HTTP server configuration, while docker-nginx-rtmp focuses primarily on RTMP functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

docker-nginx-rtmp

A Dockerfile installing NGINX, nginx-rtmp-module and FFmpeg from source with default settings for HLS live streaming. Built on Alpine Linux.

  • Nginx 1.23.1 (Mainline version compiled from source)
  • nginx-rtmp-module 1.2.2 (compiled from source)
  • ffmpeg 5.1 (compiled from source)
  • Default HLS settings (See: nginx.conf)

Docker Stars Docker Pulls Docker Automated build Build Status

Usage

Server

  • Pull docker image and run:
docker pull alfg/nginx-rtmp
docker run -it -p 1935:1935 -p 8080:80 --rm alfg/nginx-rtmp

or

  • Build and run container from source:
docker build -t nginx-rtmp .
docker run -it -p 1935:1935 -p 8080:80 --rm nginx-rtmp
  • Stream live content to:
rtmp://localhost:1935/stream/$STREAM_NAME

SSL

To enable SSL, see 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. 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 from Let's Encrypt.

Environment Variables

This Docker image uses envsubst for environment variable substitution. You can define additional environment variables in nginx.conf as ${var} and pass them in your docker-compose file or docker command.

Custom nginx.conf

If you wish to use your own nginx.conf, mount it as a volume in your docker-compose or docker command as nginx.conf.template:

volumes:
  - ./nginx.conf:/etc/nginx/nginx.conf.template

OBS Configuration

  • Stream Type: Custom Streaming Server
  • URL: rtmp://localhost:1935/stream
  • Stream Key: hello

Watch Stream

  • 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
  • FFplay: ffplay -fflags nobuffer rtmp://localhost:1935/stream/hello

FFmpeg Build

$ ffmpeg -buildconf

ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.1 (Alpine 10.2.1_pre1) 20201203
  configuration: --prefix=/usr/local --enable-version3 --enable-gpl --enable-nonfree --enable-small --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libvpx --enable-libtheora --enable-libvorbis --enable-libopus --enable-libfdk-aac --enable-libass --enable-libwebp --enable-postproc --enable-avresample --enable-libfreetype --enable-openssl --disable-debug --disable-doc --disable-ffplay --extra-libs='-lpthread -lm'
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100

  configuration:
    --prefix=/usr/local
    --enable-version3
    --enable-gpl
    --enable-nonfree
    --enable-small
    --enable-libmp3lame
    --enable-libx264
    --enable-libx265
    --enable-libvpx
    --enable-libtheora
    --enable-libvorbis
    --enable-libopus
    --enable-libfdk-aac
    --enable-libass
    --enable-libwebp
    --enable-postproc
    --enable-avresample
    --enable-libfreetype
    --enable-openssl
    --disable-debug
    --disable-doc
    --disable-ffplay
    --extra-libs='-lpthread -lm'

FFmpeg Hardware Acceleration

A Dockerfile.cuda image is available to enable FFmpeg hardware acceleration via the NVIDIA's CUDA.

Use the tag: alfg/nginx-rtmp:cuda:

docker run -it -p 1935:1935 -p 8080:80 --rm alfg/nginx-rtmp:cuda

You must have a supported platform and driver to run this image.

*This image is experimental!

Resources