Serving FLV Live Streams
This guide will introduce the way to serve live streams via HTTP-FLV and WebSocket-FLV.
Step 1: Initialize a New Project and Add Required Packages
Both HTTP-FLV and WebSocket-FLV will be served via middlewares of ASP.NET Core. Create an empty ASP.NET Core Web application and add the necessary packages using the following commands:
dotnet new web
dotnet add package LiveStreamingServerNet
dotnet add package LiveStreamingServerNet.Flv
Step 2: Configure Your Live Streaming Server
Edit Program.cs
file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
This code sets up the live streaming server and the ASP.NET Core web app, while the live streaming server will run alongside the web app using port 1935. In addition, the web app will serve both HTTP-FLV and WebSocket-FLV.
Note that app.UseWebSockets()
must be added before app.UseWebSocketFlv(liveStreamingServer)
to ensure a correct WebSocket pipeline.
If CORS is required, you can add the CORS service and middleware as usual. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Step 3: Launch Your Live Streaming Server
Execute your live streaming server by running the following command:
dotnet run --urls="https://+:8080"
Now, your live streaming server should be running and ready to accept RTMP streams via port 1935.
Once a live stream is published to rtmp://localhost:1935/live/demo
, you can visit the HTTP-FLV live stream at
https://localhost:8080/live/demo.flv
or WebSocket-FLV live stream at
wss://localhost:8080/live/demo.flv