Technical Articles & Tutorials

Live Video Streaming Server with Nginx

Having an RTMP live streaming server is useful for accepting one or more incoming video streams. These streams can be rebroadcast to multiple streaming services and you could show a standby video when there is a momentary loss of connectivity. IRL (In Real Life) streamers often use these standby videos so they don’t lose viewers when they hit a cellular dead zone.

There are commercial platforms like Wowza that are easy to setup but cost hundreds of dollars per year per server in addition to server rental and bandwidth fees. There is a little known open source solution that you can use for free called Nginx and Nginx-RTMP-Module.

Ubuntu 18.04 LTS has a precompiled package for NGINX RTMP, so you can avoid having to compile NGINX and Nginx-RTMP-Module manually.

Install nginx and rtmp module

sudo apt-get install libnginx-mod-rtmp nginx -y

After installing Nginx you’ll need to change the config to activate the RTMP model. See the following sample config file. This configuration is designed to be used in combination with OBS so that OBS does a scene change with the bitrate is too low. This configuration isn’t fully secure and needs to have IP restrictions or other access controls added, otherwise anyone could stream to this server.

worker_processes 1;

events {
    worker_connections 4096;
}

http {
include mime.types;
default_type application/octet-stream;
ignore_invalid_headers on;

server {
    listen      80;
    server_name localhost;

    # This URL provides RTMP statistics in XML
    location /stat {
        if ($request_method = "GET") {
            add_header "Access-Control-Allow-Origin"  *;
        }

        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/;
        root "/";

    }

    location /control {
        rtmp_control all;
    }
}
}

rtmp {
server {
    listen 1935;
    ping 30s;
    notify_method get;
    chunk_size 8192;
    ack_window 8192;

    # Stream to "rtmp://HOSTNAME/publish/live".
    application publish {
        live on;
        wait_video on;
        wait_key on;
        exec_options on;
        publish_notify on;
        play_restart on;
        drop_idle_publisher 6s;
        idle_streams off;
    }
}
}

Restart nginx then hit http://ip-address-of-server/stat and you should see something like:

[image here]

This interface shows your active RTMP connections and bandwidth.

About

Why fear those copying you, if you are doing good they will do the same to the world.

Archives

  1. AI & Automation
  2. AI Filtering for Web Content
  3. Web Fundamentals & Infrastructure
  4. Reclaiming Connection: Decentralized Social Networks
  5. Web Economics & Discovery
  6. The Broken Discovery Machine
  7. Evolution of Web Links
  8. Code & Frameworks
  9. Breaking the Tech Debt Avoidance Loop
  10. Evolution of Scaling & High Availability
  11. Evolution of Configuration & Environment
  12. Evolution of API Support
  13. Evolution of Browser & Client Support
  14. Evolution of Deployment & DevOps
  15. Evolution of Real-time Capabilities
  16. The Visual Basic Gap in Web Development
  17. Evolution of Testing & Monitoring
  18. Evolution of Internationalization & Localization
  19. Evolution of Form Processing
  20. Evolution of Security
  21. Evolution of Caching
  22. Evolution of Data Management
  23. Evolution of Response Generation
  24. Evolution of Request Routing & Handling
  25. Evolution of Session & State Management
  26. Web Framework Responsibilities
  27. Evolution of Internet Clients
  28. Evolution of Web Deployment
  29. The Missing Architectural Layer in Web Development
  30. Development Velocity Gap: WordPress vs. Modern Frameworks
  31. Data & Storage
  32. Evolution of Web Data Storage
  33. Information Management
  34. Managing Tasks Effectively: A Complete System
  35. Managing Appointments: Designing a Calendar System
  36. Building a Personal Knowledge Base
  37. Contact Management in the Digital Age
  38. Project Management for Individuals
  39. The Art of Response: Communicating with Purpose
  40. Strategic Deferral: Purposeful Postponement
  41. The Art of Delegation: Amplifying Impact
  42. Taking Action: Guide to Decisive Execution
  43. The Art of Deletion: Digital Decluttering
  44. Digital Filing: A Clutter-Free Life
  45. Managing Incoming Information
  46. Cloud & Infrastructure
  47. AWS Lightsail versus EC2
  48. WordPress on AWS Lightsail
  49. Migrating from Heroku to Dokku
  50. Storage & Media
  51. Vultr Object Storage on Django Wagtail
  52. Live Video Streaming with Nginx
  53. YI 4k Live Streaming
  54. Tools & Connectivity
  55. Multi Connection VPN
  56. Email Forms with AWS Lambda
  57. Static Sites with Hexo

Optimize Your Website!

Is your WordPress site running slowly? I offer a comprehensive service that includes needs assessments and performance optimizations. Get your site running at its best!

Check Out My Fiverr Gig!

Elsewhere

  1. YouTube
  2. Twitter
  3. GitHub