Yesterday I talked about the new preview for Live Streaming in Azure Media Services. As we saw is quite easy to create channels from the portal, but there are situations where we need to make this process automatic and configurable through our code. The following example shows how to create a channel using Azure Media Services SDK for NET:
[csharp]using Microsoft.WindowsAzure.MediaServices.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
namespace LiveStreaming
{
class Program
{
static void Main(string[] args)
{
//0. Constants
const string AccountName = "[YOUR_ACCOUNT_NAME]";
const string AccountKey = "[YOUR_ACCOUNT_KEY]";
//1. Install Nuget packages
//1.1 Nuget: Install-Package windowsazure.mediaservices
//2. Get AMS context
var context = new CloudMediaContext(AccountName, AccountKey);
//3. Create a channel
//3.1 Create Channel Input
var input = new ChannelInput
{
StreamingProtocol = StreamingProtocol.RTMP,
AccessControl = new ChannelAccessControl
{
IPAllowList = new List<IPRange>
{
new IPRange{
Name="MyInput",
Address=IPAddress.Parse("0.0.0.0"),
SubnetPrefixLength = 0
}
}
}
};
//3.2 Create Channel Preview
var preview = new ChannelPreview
{
AccessControl = new ChannelAccessControl
{
IPAllowList = new List<IPRange>()
{
new IPRange{
Name= "MyPreview",
Address = IPAddress.Parse("0.0.0.0"),
SubnetPrefixLength = 0
}
}
}
};
//3.3 Create Channel Output
var output = new ChannelOutput { Hls = new ChannelOutputHls { FragmentsPerSegment = 1 } };
var channel = context.Channels.Create(new ChannelCreationOptions
{
Name = "Channel-Returngis-1",
Input = input,
Preview = preview,
Output = output
});
channel.Start();
var previewEndpoint = channel.Preview.Endpoints.FirstOrDefault().Url.ToString();
var ingestEndpoint = channel.Input.Endpoints.FirstOrDefault().Url.ToString();
Console.WriteLine("The channel {0} is {1}", channel.Name, channel.State);
Console.WriteLine("Ingest endpoint: {0}",ingestEndpoint);
Console.WriteLine("Preview endpoint: {0}",previewEndpoint);
Console.ReadLine();
}
}
}
[/csharp]
- Azure Media Services credentials are needed.
- Install the windowsazure.mediaservices via Nuget
- Get the context of the account.
- To generate the channel we need:
- Create the ingest endpoint through ChannelInput, selecting the protocol to use and the range of IPs from which you can perform ingest. If we use 0.0.0.0 we are giving public access to it.
- Endpoint to access the preview channel, where we only add the IP range allowed.
- Finally, it is necessary to create the output through ChannelOutput.
- Once we have the ingest and the preview endpoints we can create the channel through context.Channels.Create and start it through the Start() method. When the process finishes we can recover the ingest and preview URLs to begin testing the new channel.
Happy live streaming!

how to attach camera to channel to give input?
Hi Nasheed, you need an encoder that connects your camera with Azure Media Services. The most common encoders are Flash Media Live Encoder, Wirecast, etc.
Please, take a look at this article: https://www.returngis.net/2014/09/microsoft-azure-media-services-live-streaming/
Hope it helps.
Thnku…can we use azure media encoder for this purpose through .net sdk?
Any sample would be very usefull
Hi Gisela…I am student of computer sciences and I pick the «web conferencing system through azure media services .NET SDK» as my class project..can u provide me some sample or guidaance for my project,I am very new in streaming don’t even know proper workflow?