4. Create live channel and start the Channel. Channels are the fundamental entity in Azure Media Services that allows you to ingest a live stream. Each Channel will have an ingest URL and a preview URL, it can also have one or more Programs associated with it. It usually takes around 2 minutes to start a Channel but could take as much as 20 minutes. You don’t have to start the Channel right away, usually people set up the Channel in advance but wait to start it until their live event is about to start.

5. We will implement each of the methods in part 4. Here is how to create a Channel. When creating a Channel you can choose the ingest protocol it supports either Fragmented Mp4 (Smooth Streaming) or RTMP. In Access Control, you will need to define IP allow list to permit Ingest point access, you can either lock it down to your specific machine or open it to a range of IP addresses. To open it to all IP addresses set it to “0.0.0.0/0”.

7. Putting the following lines into main to create Channel, and print out ingest URL and Preview URL. Ingest URL is the push destination you will give to your live encoder (please refer to Live encoder configuration blog if you want to set up encoder such as Wirecast). Once you have configured your live encoder and started it, you should be able to watch the stream from Preview URL in order to verify that your stream is being ingested properly.

IChannel channel = CreateAndStartChannel();
// Set the Live Encoder to point to the channel's input endpoint:
Console.WriteLine("Channel's ingest URL " + channel.Input.Endpoints.FirstOrDefault().Url.ToString());
// Use the previewEndpoint to preview and verify
// that the input from the encoder is actually reaching the Channel.
Console.WriteLine("Channel's preview URL " + channel.Preview.Endpoints.FirstOrDefault().Url.ToString());

8. If you want to persist your stream and make it available to your audience you need to create a Program and Streaming Endpoint. Let’s put the following code into the Main method.

// Once you previewed your stream and verified that it is flowing into your Channel,
// you can create an event by creating an Asset, Program, and Streaming Locator.
IProgram program = CreateAndStartProgram(channel);
ILocator locator = CreateLocatorForAsset(program.Asset, program.ArchiveWindowLength);
IStreamingEndpoint streamingEndpoint = CreateAndStartStreamingEndpoint();
GetLocatorsInAllStreamingEndpoints(program.Asset);
Console.ReadLine();

9. A Program enables you to control the publishing and storage of a live stream. You can run up to three Programs concurrently, this allows you to publish and archive different parts of the stream as needed. You can specify the number of hours you want to retain the recorded content for the Program by setting the ArchiveWindowLength property. This value can be set from a minimum of 5 minutes to a maximum of 25 hours. This also dictates the maximum amount of time viewers can seek back in time from the current live position. Programs can run over the specified amount of time, but content that falls behind the window length is continuously discarded.

public static IProgram CreateAndStartProgram(IChannel channel)
{
IAsset asset = _context.Assets.Create(AssetlName, AssetCreationOptions.None);
// Create a Program on the Channel. You can have multiple Programs that overlap or are sequential;
// however each Program must have a unique name within your Media Services account.
IProgram program = channel.Programs.Create(ProgramlName, TimeSpan.FromHours(3), asset.Id);
program.Start();
Console.WriteLine("Starting Program " + Program.ProgramlName);
return program;
}

10. After that, you must create a Streaming Locator in order to access the stream. The Streaming Locator makes the Asset you associated with your Program available for streaming through your Streaming Endpoint. When creating your Streaming Locator you can set an access policy for the streaming access to the Asset.

11. Lastly, you need to create a Streaming Endpoint and get the locator URL. A single Media Services account can have multiple Streaming Endpoints. You may want to have multiple Streaming Endpoints if you want to have different configurations for each (for example, security settings, cross site access policies, scale units, etc.) or if you want to separate your Video on Demand (VOD) and Live streaming.