Convert Figma logo to code with AI

sergey-dryabzhinsky logonginx-rtmp-module

NGINX-based Media Streaming Server

1,021
216
1,021
155

Top Related Projects

NGINX-based Media Streaming Server

A media streaming server based on nginx-rtmp-module. In addtion to the features nginx-rtmp-module provides, HTTP-FLV, GOP cache, VHosts (one IP for multi domain names) and JSON style statistics are supported now.

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

25,534

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

The nginx-rtmp-module is an RTMP/HLS/DASH module for Nginx, providing streaming capabilities. It allows Nginx to function as a streaming server for live and on-demand audio and video content using popular streaming protocols.

Pros

  • Supports multiple streaming protocols (RTMP, HLS, DASH)
  • Integrates seamlessly with Nginx, a widely-used web server
  • Offers low-latency streaming capabilities
  • Provides features like recording, transcoding, and stream authentication

Cons

  • Requires compilation from source, which may be challenging for some users
  • Documentation could be more comprehensive and up-to-date
  • Limited built-in monitoring and analytics features
  • May require additional configuration for optimal performance in high-load scenarios

Code Examples

  1. Basic RTMP server configuration:
rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            record off;
        }
    }
}

This code sets up a basic RTMP server listening on port 1935 with live streaming enabled.

  1. HLS streaming configuration:
rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application hls {
            live on;
            hls on;
            hls_path /tmp/hls;
            hls_fragment 3s;
            hls_playlist_length 60s;
        }
    }
}

This configuration enables HLS streaming, storing fragments in the /tmp/hls directory with 3-second fragments and a 60-second playlist length.

  1. Stream authentication example:
rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application secure {
            live on;
            on_publish http://auth.example.com/auth;
        }
    }
}

This code adds authentication to the RTMP stream by calling an external HTTP endpoint before allowing publishing.

Getting Started

  1. Clone the repository:

    git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git
    
  2. Download and extract Nginx source:

    wget http://nginx.org/download/nginx-1.21.6.tar.gz
    tar -xzf nginx-1.21.6.tar.gz
    
  3. Compile Nginx with the RTMP module:

    cd nginx-1.21.6
    ./configure --add-module=../nginx-rtmp-module
    make
    sudo make install
    
  4. Configure Nginx with RTMP settings (see code examples above)

  5. Start Nginx:

    sudo nginx
    

Competitor Comparisons

NGINX-based Media Streaming Server

Pros of nginx-rtmp-module (arut)

  • More active development and maintenance
  • Better support for modern RTMP features
  • Larger community and more frequent updates

Cons of nginx-rtmp-module (arut)

  • Potentially less stable due to frequent changes
  • May require more frequent adjustments to keep up with updates

Code Comparison

nginx-rtmp-module (arut):

ngx_rtmp_stat_bw(ngx_http_request_t *r, ngx_chain_t ***lll,
    ngx_rtmp_bandwidth_t *bw, char *name,
    ngx_uint_t flags)
{
    ngx_chain_t        *cl;
    ngx_uint_t          speed;
    u_char             *p, *pe;
    ngx_str_t           buf;

nginx-rtmp-module (sergey-dryabzhinsky):

ngx_rtmp_stat_bw(ngx_http_request_t *r, ngx_chain_t ***lll,
    ngx_rtmp_bandwidth_t *bw, char *name)
{
    ngx_chain_t        *cl;
    ngx_uint_t          speed;
    u_char             *p, *pe;
    ngx_str_t           buf;

The main difference in the code snippet is the addition of the flags parameter in the arut version, which allows for more flexible configuration options.

Both modules provide RTMP functionality for Nginx, but the arut version is generally considered more up-to-date and feature-rich. However, the sergey-dryabzhinsky version may offer more stability for those who prefer less frequent updates.

A media streaming server based on nginx-rtmp-module. In addtion to the features nginx-rtmp-module provides, HTTP-FLV, GOP cache, VHosts (one IP for multi domain names) and JSON style statistics are supported now.

Pros of nginx-http-flv-module

  • Supports HTTP-FLV streaming, which can be more compatible with web browsers and CDNs
  • Includes additional features like GOP cache and HTTP callbacks
  • More actively maintained with recent updates and bug fixes

Cons of nginx-http-flv-module

  • May have a steeper learning curve due to additional configuration options
  • Potentially higher resource usage due to extra features
  • Less widespread adoption compared to the RTMP module

Code Comparison

nginx-rtmp-module:

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

nginx-http-flv-module:

http {
    server {
        listen 80;
        location /live {
            flv_live on;
            chunked_transfer_encoding on;
        }
    }
}
rtmp {
    server {
        listen 1935;
        application live {
            live on;
            http_flv on;
        }
    }
}

The nginx-http-flv-module configuration includes both RTMP and HTTP-FLV settings, providing more flexibility but requiring additional setup. The nginx-rtmp-module configuration is simpler but limited to RTMP streaming.

Both modules offer robust streaming capabilities, with nginx-http-flv-module providing more features and HTTP-FLV support at the cost of increased complexity. The choice between them depends on specific project requirements and the desired balance between simplicity and advanced functionality.

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

Pros of docker-nginx-rtmp

  • Containerized solution, easier to deploy and manage
  • Includes a pre-configured Nginx RTMP module
  • Provides a ready-to-use Docker image

Cons of docker-nginx-rtmp

  • Less flexibility for custom configurations
  • May have performance overhead due to containerization
  • Limited to the specific Nginx and RTMP module versions in the image

Code Comparison

nginx-rtmp-module:

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            record off;
        }
    }
}

docker-nginx-rtmp:

FROM tiangolo/nginx-rtmp

COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 1935
EXPOSE 8080

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

The nginx-rtmp-module repository provides the core RTMP module for Nginx, allowing users to configure it directly within their Nginx setup. On the other hand, docker-nginx-rtmp offers a pre-configured Docker image with the RTMP module already integrated, simplifying deployment but potentially limiting customization options.

While nginx-rtmp-module requires manual configuration and integration with an existing Nginx installation, docker-nginx-rtmp provides a turnkey solution that can be quickly deployed using Docker. However, this convenience comes at the cost of reduced flexibility in terms of version control and fine-tuning the RTMP module configuration.

25,534

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 feature set, including support for multiple streaming protocols (RTMP, HLS, WebRTC, etc.)
  • Active development with frequent updates and improvements
  • Better documentation and community support

Cons of SRS

  • More complex setup and configuration compared to the nginx-rtmp-module
  • Potentially higher resource usage due to its broader feature set

Code Comparison

nginx-rtmp-module configuration:

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

SRS configuration:

listen              1935;
max_connections     1000;
srs_log_tank        file;
srs_log_file        ./objs/srs.log;
http_api {
    enabled         on;
    listen          1985;
}
vhost __defaultVhost__ {
}

The nginx-rtmp-module configuration is simpler and more straightforward, while SRS offers more detailed configuration options out of the box. SRS provides built-in HTTP API support and more granular control over logging and connections.

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

NGINX-based Media Streaming Server

nginx-rtmp-module

Project blog

http://nginx-rtmp.blogspot.com

Documentation

Source: https://github.com/arut/nginx-rtmp-module/wiki

Google group

https://groups.google.com/group/nginx-rtmp

https://groups.google.com/group/nginx-rtmp-ru (Russian)

Donation page (Paypal etc)

http://arut.github.com/nginx-rtmp-module/

Features

  • RTMP/HLS/MPEG-DASH live streaming

  • RTMP Video on demand FLV/MP4, playing from local filesystem or HTTP

  • Stream relay support for distributed streaming: push & pull models

  • Recording streams in multiple FLVs

  • H264/AAC support

  • Online transcoding with FFmpeg

  • HTTP callbacks (publish/play/record/update etc)

  • Running external programs on certain events (exec)

  • HTTP control module for recording audio/video and dropping clients

  • Advanced buffering techniques to keep memory allocations at a minimum level for faster streaming and low memory footprint

  • Proved to work with Wirecast, FMS, Wowza, JWPlayer, FlowPlayer, StrobeMediaPlayback, ffmpeg, avconv, rtmpdump, flvstreamer and many more

  • Statistics in XML/XSL in machine- & human- readable form

  • Linux/FreeBSD/MacOS/Windows

Build

cd to NGINX source directory & run this:

./configure --add-module=/path/to/nginx-rtmp-module
make
make install

Several versions of nginx (1.3.14 - 1.5.0) require http_ssl_module to be added as well:

./configure --add-module=/path/to/nginx-rtmp-module --with-http_ssl_module

For building debug version of nginx add --with-debug

./configure --add-module=/path/to-nginx/rtmp-module --with-debug

Read more about debug log

Contributing and Branch Policy

The "dev" branch is the one where all contributions will be merged before reaching "master". If you plan to propose a patch, please commit into the "dev" branch or its own feature branch. Direct commit to "master" are not permitted.

Windows limitations

Windows support is limited. These features are not supported

  • execs
  • static pulls
  • auto_push

RTMP URL format

rtmp://rtmp.example.com/app[/name]

app - should match one of application {} blocks in config

name - interpreted by each application can be empty

Multi-worker live streaming

This NGINX-RTMP module does not support multi-worker live streaming. While this feature can be enabled through rtmp_auto_push on|off directive, it is ill advised because it is incompatible with NGINX versions starting 1.7.2 and up, there for it should not be used.

Example nginx.conf

rtmp {

    server {

        listen 1935;

        chunk_size 4000;

        # TV mode: one publisher, many subscribers
        application mytv {

            # enable live streaming
            live on;

            # record first 1K of stream
            record all;
            record_path /tmp/av;
            record_max_size 1K;

            # append current timestamp to each flv
            record_unique on;

            # publish only from localhost
            allow publish 127.0.0.1;
            deny publish all;

            #allow play all;
        }

        # Transcoding (ffmpeg needed)
        application big {
            live on;

            # On every published stream run this command (ffmpeg)
            # with substitutions: $app/${app}, $name/${name} for application & stream name.
            #
            # This ffmpeg call receives stream from this application &
            # reduces the resolution down to 32x32. The stream is the published to
            # 'small' application (see below) under the same name.
            #
            # ffmpeg can do anything with the stream like video/audio
            # transcoding, resizing, altering container/codec params etc
            #
            # Multiple exec lines can be specified.

            exec ffmpeg -re -i rtmp://localhost:1935/$app/$name -vcodec flv -acodec copy -s 32x32
                        -f flv rtmp://localhost:1935/small/${name};
        }

        application small {
            live on;
            # Video with reduced resolution comes here from ffmpeg
        }

        application webcam {
            live on;

            # Stream from local webcam
            exec_static ffmpeg -f video4linux2 -i /dev/video0 -c:v libx264 -an
                               -f flv rtmp://localhost:1935/webcam/mystream;
        }

        application mypush {
            live on;

            # Every stream published here
            # is automatically pushed to
            # these two machines
            push rtmp1.example.com;
            push rtmp2.example.com:1934;
        }

        application mypull {
            live on;

            # Pull all streams from remote machine
            # and play locally
            pull rtmp://rtmp3.example.com pageUrl=www.example.com/index.html;
        }

        application mystaticpull {
            live on;

            # Static pull is started at nginx start
            pull rtmp://rtmp4.example.com pageUrl=www.example.com/index.html name=mystream static;
        }

        # video on demand
        application vod {
            play /var/flvs;
        }

        application vod2 {
            play /var/mp4s;
        }

        # Many publishers, many subscribers
        # no checks, no recording
        application videochat {

            live on;

            # The following notifications receive all
            # the session variables as well as
            # particular call arguments in HTTP POST
            # request

            # Make HTTP request & use HTTP retcode
            # to decide whether to allow publishing
            # from this connection or not
            on_publish http://localhost:8080/publish;

            # Same with playing
            on_play http://localhost:8080/play;

            # Publish/play end (repeats on disconnect)
            on_done http://localhost:8080/done;

            # All above mentioned notifications receive
            # standard connect() arguments as well as
            # play/publish ones. If any arguments are sent
            # with GET-style syntax to play & publish
            # these are also included.
            # Example URL:
            #   rtmp://localhost/myapp/mystream?a=b&c=d

            # record 10 video keyframes (no audio) every 2 minutes
            record keyframes;
            record_path /tmp/vc;
            record_max_frames 10;
            record_interval 2m;

            # Async notify about an flv recorded
            on_record_done http://localhost:8080/record_done;

        }


        # HLS

        # For HLS to work please create a directory in tmpfs (/tmp/hls here)
        # for the fragments. The directory contents is served via HTTP (see
        # http{} section in config)
        #
        # Incoming stream must be in H264/AAC. For iPhones use baseline H264
        # profile (see ffmpeg example).
        # This example creates RTMP stream from movie ready for HLS:
        #
        # ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264
        #    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
        #    -f flv rtmp://localhost:1935/hls/movie
        #
        # If you need to transcode live stream use 'exec' feature.
        #
        application hls {
            live on;
            hls on;
            hls_path /tmp/hls;
        }

        # MPEG-DASH is similar to HLS

        application dash {
            live on;
            dash on;
            dash_path /tmp/dash;
        }
    }
}

# HTTP can be used for accessing RTMP stats
http {

    server {

        listen      8080;

        # This URL provides RTMP statistics in XML
        location /stat {
            rtmp_stat all;

            # Use this stylesheet to view XML as web page
            # in browser
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            # XML stylesheet to view RTMP stats.
            # Copy stat.xsl wherever you want
            # and put the full directory path here
            root /path/to/stat.xsl/;
        }

        location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /tmp;
            add_header Cache-Control no-cache;
        }

        location /dash {
            # Serve DASH fragments
            root /tmp;
            add_header Cache-Control no-cache;
        }
    }
}