Build your own self-hosted live streaming application with Owncast and .NET Aspire

Platforms come and go. As a result, I'm a strong advocate for owning your data (when possible). Self-hosting is a way for you to do that. Owning your data could mean self-hosting your website, password manager, media server, or social media. However, self-hosting comes with its own challenges, primarily cost (time and money) and in cases where software isn't provided as an appliance on your hosting provider of choice, some technical knowledge may be required.

As I got more into self-hosting applications such as my Mastodon instance, I came across Owncast.

During peak COVID lockdowns, like many others, live streaming is one of the ways I passed the time. While Twitch and YouTube got the job done, self-hosting was always in the back of my mind.

It's been a while since I've live-streamed, so I never really went through the process of evaluating the self-hosted route with Owncast.

While browsing for something on YouTube the other day, I ran into some of my old live-stream recordings. This got me thinking again, how difficult would it be to put together my own live-streaming setup.

This post is the result of that exploration.

In this post, I'll modify a .NET Aspire Starter Application template and show how to set up a self-hosted live-streaming application using Owncast and .NET Aspire.

You can find the source code in the lqdev/BYOwncastAspire repository.

BYOwnCastAspire Web Frontend

What is Owncast?

The Owncast website describes the project as, "...a free and open source live video and web chat server for use with existing popular broadcasting software."

Owncast admin server page

It goes on to further describe some of the reasons I like Owncast, which are:

To learn more, check out the Owncast website.

What is .NET Aspire?

The .NET Aspire documentation describes it as, "...an opinionated, cloud ready stack for building observable, production ready, distributed applications.​ .NET Aspire is delivered through a collection of NuGet packages that handle specific cloud-native concerns."

Personally, the parts of .NET Aspire that matter to me are:

Although in this post, I don't cover deployment, there is also the provisioning component provided by .NET Aspire which in many cases can simplify your application deployments.

To learn more, check out the .NET Aspire documentation.

Build your application

This application makes a few modifications to the .NET Aspire Starter Application template.

The application consists of a few projects:

Configure Owncast

There are many ways to host an Owncast server, with one of them being a container.

In the context of Aspire which has built-in container support, you can easily add Owncast as a resource in your application.

From the Owncast documentation, once you've pulled the Owncast container image, you can start it with the following command.

docker run -v `pwd`/data:/app/data -p 8080:8080 -p 1935:1935 owncast/owncast:latest

This translates to the following in the Program.cs of the BYOwncastAspire.AppHost project.

var owncast = builder
    .AddContainer(name: "owncast", image:"owncast/owncast")
    .WithBindMount("./data","/app/data")
    .WithHttpEndpoint(port:8080,targetPort:8080,name:"admin")
    .WithHttpEndpoint(port:1935,targetPort:1935,name:"streaming")
    .WithExternalHttpEndpoints();

This code:

Embed your stream

Owncast provides the ability to embed your video stream onto a website.

Although we don't need a frontend because one is already provided by Owncast, by embedding your stream on your website you can provide a single place for your viewers to consume your content.

In this case, we can treat the BYOwncastAspire.Web project as our website.

To embed your stream to the website, add the following code to your Home.razor page.

<iframe
  src="http://localhost:8080/embed/video"
  title="Owncast"
  height="350px" width="550px"
  referrerpolicy="origin"
  allowfullscreen>
</iframe>

In this case, we're pointing to the endpoint listening on port 8080 of our localhost. When you deploy the application, you'd replace src with your domain.

Start your application

That's all there is in terms of configuration.

To start the application:

  1. Open the terminal

  2. Navigate to the BYOwncastAspire.AppHost project and run the following command.

    dotnet run
    

This will launch you into the .NET Aspire dashboard. At this point, you can further customize your Owncast server as well as the website.

BYOwncastAspire .NET Aspire Dashboard Resource Page

What next?

Now that you have your application running, in its current form, this application is only meant to serve as a sample of what you can do with Owncast and .NET Aspire.

Some next steps might include:

The plugins and extensions are particularly interesting to me because there may even be opportunities to experiment and insert AI capabilities at various layers such as moderation, translation, accessibility, show notes, chat summaries, etc.

Conclusion

In this post, I showed how you can combine the powerful live-steaming features of Owncast with the app orchestration and tooling in .NET Aspire to create rich self-hosted live-steaming applications.

If you use this sample as a starting point for your own live-streaming or self-hosting explorations, send me a message. I'd love to hear about it.


Send me a message or webmention