Going live on localhost with NGINX and RTMP module

After a break from Class To Cloud, I’ve repicked the project to add more features that I intended for it. One of them was live streaming support for the app. So this post is about my explorations of the Livestreaming system and how the system works when you click go live on any social platform.

A while back, I started exploring livestreaming solutions for Class to Cloud. The idea was simple: enable coaching institutes to broadcast live sessions while ensuring smooth playback and minimal latency. I wanted something lightweight, reliable, and self-hosted—so naturally, I landed on NGINX with the RTMP module.

Why NGINX RTMP?

There are tons of streaming solutions out there, but NGINX RTMP is free, open-source, and gives complete control over the livestreaming process. Plus, it integrates well with existing setups without bloating the system with unnecessary services.

This works on the RTMP Protocol (Real-Time Messaging Protocol). RTMP is a technology developed by Macromedia (now Adobe) to deliver high-performance video, audio, and data over the internet with low latency. It is widely used for live streaming because of its ability to maintain persistent, real-time connections between a media server and a client.

Setting up the NGINX Server

To start, I had to set up an NGINX RTMP server on my machine. Here’s how I did it:

1. Installing NGINX with RTMP Module

Since the standard NGINX installation doesn’t come with RTMP support, I had to install it manually with the required module.

<span>sudo </span>apt update <span>&&</span> <span>sudo </span>apt <span>install</span> <span>-y</span> nginx libnginx-mod-rtmp
<span>sudo </span>apt update <span>&&</span> <span>sudo </span>apt <span>install</span> <span>-y</span> nginx libnginx-mod-rtmp
sudo apt update && sudo apt install -y nginx libnginx-mod-rtmp

Enter fullscreen mode Exit fullscreen mode

Once installed, I configured the rtmp.conf file to define the stream settings.

2. Configuring NGINX for RTMP

I edited the NGINX configuration file to enable RTMP streaming. Here’s the configuration I used:

This file has been set up in such a way that I can later add the FFmpeg command to save the stream in multiple resolutions.

After configuring, I restarted the NGINX server:

<span>sudo </span>systemctl restart nginx
<span>sudo </span>systemctl restart nginx
sudo systemctl restart nginx

Enter fullscreen mode Exit fullscreen mode

Streaming Video through OBS

After the server was ready, I quickly started OBS Studio for live streaming the content.

Streaming through OBS

After setting up the stream, I tested it by opening VLC Media Player. I navigated to Media > Open Network Stream, entered the stream URL:

rtmp://localhost:1935/stream/test
rtmp://localhost:1935/stream/test
rtmp://localhost:1935/stream/test

Enter fullscreen mode Exit fullscreen mode

and hit play. Within moments, the live stream started playing smoothly, confirming that the RTMP setup was working as expected. Seeing the stream run in real-time was a rewarding moment after all the configuration work.

Transcoding and Saving the Stream

I ran a separate command for transcoding the stream. Later, I will integrate it inside the RTMP server itself so that it will only take one step.

Command for transcoding into 320×180 resolution:

The transcoded files

The above command generates a lower-resolution version of the stream, which will help optimize bandwidth usage for viewers with slower internet connections.

Final Thoughts

With the core streaming functionality in place, I feel more confident moving forward with deeper integration into Class to Cloud. This journey into livestreaming has been eye-opening, and there’s still much to refine. In the next phase, I’ll focus on incorporating user authentication, optimizing playback, and making the livestreaming feature as seamless as possible for coaching institutes. Stay tuned!

TLDR

  • Set up an NGINX RTMP server to enable live streaming.
  • Configured OBS Studio to stream to the RTMP server.
  • Verified the livestream using VLC Media Player.
  • Enabled recording of livestreams for later playback.
  • Next step: Integrate this feature into Class to Cloud to make it seamless for students and teachers.

原文链接:Going live on localhost with NGINX and RTMP module

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
Hard-working is actually a cool thing.
努力学习其实是一件很酷的事
评论 抢沙发

请登录后发表评论

    暂无评论内容