Live Video Streaming - Azure Media Services

written in azure, live streaming

Live streaming with Azure Media Services and YouTube, how hard can it be?

Recently I have been working on redesigning my church’s website (sneak preview here), with the new design I wanted to update the technology that we use for our live broadcasts of the Sunday services.

We use Influxis as our streaming provider which costs around £200 per year. As we started live streaming several years ago our current plan isn’t offered anymore and if we wanted to update to a newer plan the cheapest is $95 per month, which is too expensive; considering it is only used twice on a Sunday.

There are several other reasons why I wanted to look into other options:

  • Our plan only permitted 20 simultaneous connections
  • As our plan is no longer offered, we are also stuck with a broken admin portal, many of the features are missing.
  • It is flash based, so only really works properly on desktops
  • Quality is poor with limited bandwidth permitted by the plan.

Once I had completed the new design for the site, my next task was to look into new streaming options. My first port of call was Azure Media Services

Azure Media Services

Azure Media Services provide the capability to stream live events using the Azure cloud platform.

To get started I followed the guide here, it guides you through a step by step process on starting live streaming using the Azure portal.

We use Flash Media Live Encoder as our program of choice for broadcasting the stream and I was keen to continue using it, as there are other people in the church that help with the broadcasts and I wanted the impact on them to be as small as possible. I followed the guide here to configure FMLE.

Following the steps above enabled me to get a live stream up and running without too much pain, however as I said before there are other less technical people who help with the broadcast and I needed to make a simple process to start and stop streaming in Azure.

Media Services REST API

To start and stop streaming without using the portal, I decided to use the Media Services REST API this provides all the necessary endpoints for creating the resources you need in Azure. The tricky part was determining what resources I actually needed, after a lot of experimentation here are the calls necessary for a live stream:

  1. First you need to get an access token, a guide on how to do that is here.
  2. You then need to make a request to https://media.windows.net/ which should respond with a 301 code and a redirect url, this is the url that you need to use for all subsequent calls to the REST API.
  3. Start the StreamingEndpoint
  4. Start the Channel
  5. Create an Asset
  6. Create a Program
  7. Start the Program
  8. Create an Access policy
  9. Create a Locator
  10. Retrieve the AssetFile

The last step is necessary for determining the publish URL i.e. the URL that the stream will be playing at, it has a format like:

http://account_name.origin.mediaservices.windows.net/locator_guid/stream_guid.ism/manifest

You can then test your stream by pasting your publish url into http://dashplayer.azurewebsites.net/ which will play the stream for you.

As you can see there were a lot of steps required just to get setup for streaming, what annoyed me was that in the Azure portal this process was only a few mouse clicks!

Luckily for everyone else I have created a java app that can start and tear down the resources in Azure, it is available on GitHub here. If you want to know more details on the content of all the requests and responses and how they are used have a look at the source code.

Conclusion

After all this work I had finally got a rough process in place that would allow someone to make a few mouse clicks and have the streaming running live in Azure. However there is a problem, Azure is expensive for this kind of stuff, in fact most cloud platforms are expensive for media encoding and streaming. In the time it took me to create the app which consisted of creating and tearing down resources, and very little streaming I had ate into £10 of my Azure credit.

This worried me, I have £65 per month of credit that I can use and I would be streaming about 10 hours a month. I’m hoping that the cost was down to me starting and stopping resources and in the real world the actual cost will be much less. I will update this post with the actual cost per hour once we move to the new streaming system.

I think Azure is a viable option, provided it is cost effective. Other cloud platforms require a 3rd party application to be installed in an instance for live streaming, but Azure supports it out of the box.

However I decided that I needed a backup solution incase we ever run out of credit or I get moved to a non C# project in work and lose my MSDN Subscription (fingers crossed!), for that I turned to YouTube and it’s Live Stream API. I will cover my YouTube solution in my next blog post.

In the meantime you can check out the code for the new Saintfield Baptist website on GitHub - https://github.com/matthewcodes/SaintfieldBaptistChurch. My LiveVideoPlayer component created using React.js may also be of interest.


Comments