josephnhtam / live-streaming-server-net

A .NET implementation of RTMP live streaming server, supporting HTTP-FLV, WebSocket-FLV, HLS, Kubernetes, cloud storage services integration and more.
https://josephnhtam.github.io/live-streaming-server-net/
MIT License
74 stars 11 forks source link
asp-net-core autoscaling cloud-native csharp dash dotnet dotnet-library flv hls http-flv kubernetes live-streaming livestream remuxing rtmp rtmp-server websocket-flv

Live-Streaming-Server-Net

build and test Nuget License: MIT

Live-Streaming-Server-Net is a high-performance and flexible toolset that allows you to build your own live streaming server using .NET.

Please check the documentation for more details.

Features

In-Progress

Roadmap

Quick Start

Run the RTMP Server

Create a .NET 8 console application project and add the dependencies

dotnet new console
dotnet add package LiveStreamingServerNet
dotnet add package Microsoft.Extensions.Logging.Console

Program.cs

using LiveStreamingServerNet;
using Microsoft.Extensions.Logging;
using System.Net;

using var server = LiveStreamingServerBuilder.Create()
    .ConfigureLogging(options => options.AddConsole())
    .Build();

await server.RunAsync(new IPEndPoint(IPAddress.Any, 1935));

Run the application

dotnet run

Publish a Live Stream

With FFmpeg

Use the following command to publish a video as the live stream using FFmpeg

ffmpeg -re -i <input_file> -c:v libx264 -c:a aac -f flv rtmp://localhost:1935/live/demo

With OBS Studio

  1. Open OBS Studio and go to "Settings".
  2. In the "Settings" window, select the "Stream" tab.
  3. Choose "Custom" as the "Service".
  4. Enter "Server": rtmp://localhost:1935/live and "Stream Key": demo.
  5. Click "OK" to save the settings.
  6. Click the "Start Streaming" button in OBS Studio to begin sending live stream to the RTMP server.

Play the Live Stream

With FFplay

Use the following command to play the live stream using FFplay

ffplay rtmp://localhost:1935/live/demo

With VLC Media Player

  1. Open VLC Media Player.
  2. Go to the "Media" menu and select "Open Network Stream".
  3. In the "Network" tab, enter the URL: rtmp://localhost:1935/live/demo.
  4. Click the "Play" button to start playing the live stream.

Serve FLV Live Streams

Create a ASP.NET CORE 8 Web API application project and add the dependencies

dotnet new webapi
dotnet add package LiveStreamingServerNet
dotnet add package LiveStreamingServerNet.Flv

Program.cs

using System.Net;
using LiveStreamingServerNet;
using LiveStreamingServerNet.Flv.Installer;
using LiveStreamingServerNet.Networking.Helpers;

using var liveStreamingServer = LiveStreamingServerBuilder.Create()
    .ConfigureRtmpServer(options => options.AddFlv())
    .ConfigureLogging(options => options.AddConsole())
    .Build();

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddBackgroundServer(liveStreamingServer, new IPEndPoint(IPAddress.Any, 1935));

var app = builder.Build();

app.UseWebSockets();
app.UseWebSocketFlv(liveStreamingServer);

app.UseHttpFlv(liveStreamingServer);

await app.RunAsync();

Run the application

dotnet run --urls="https://+:8080"

Play FLV Live Streams

Given a live stream is published to rtmp://localhost:1935/live/demo

HTTP-FLV

https://localhost:8080/live/demo.flv

WebSocket-FLV

wss://localhost:8080/live/demo.flv

Remux RTMP Streams into HLS Streams with FFmpeg

Please refer to the LiveStreamServerNet.HlsDemo

Admin Panel

Admin Panel

HTTP-FLV Preview

Please refer to the LiveStreamServerNet.StandaloneDemo

NuGet Packages

Package Latest Version
LiveStreamingServerNet
LiveStreamingServerNet.Standalone
LiveStreamingServerNet.AdminPanelUI
LiveStreamingServerNet.Flv
LiveStreamingServerNet.Networking
LiveStreamingServerNet.Rtmp
LiveStreamingServerNet.StreamProcessor
LiveStreamingServerNet.StreamProcessor.AmazonS3
LiveStreamingServerNet.StreamProcessor.AzureBlobStorage
LiveStreamingServerNet.StreamProcessor.GoogleCloudStorage
LiveStreamingServerNet.Utilities

License

This project is licensed under the terms of the MIT license.

Acknowledgments

Special thanks to JetBrains for providing the open-source software license that supports the development of this project.