Tutorial: Encode a remote file based on URL and stream the video - .NET

media services logo v3

Looking for Media Services v2 documentation?

This tutorial shows you how easy it is to encode and start streaming videos on a wide variety of browsers and devices using Azure Media Services. An input content can be specified using HTTPS URLs, SAS URLs, or paths to files located in Azure Blob storage. The sample in this topic encodes content that you make accessible via an HTTPS URL. Note that currently, AMS v3 does not support chunked transfer encoding over HTTPS URLs.

By the end of the tutorial you will be able to stream a video.

Play the video

If you don't have an Azure subscription, create a free account before you begin.


Download and configure the sample

Clone a GitHub repository that contains the streaming .NET sample to your machine using the following command:

git clone https://github.com/Azure-Samples/media-services-v3-dotnet-quickstarts.git

The sample is located in the EncodeAndStreamFiles folder under AMSV3Quickstarts.

Open appsettings.json in your downloaded project. Replace the values with credentials that you got from accessing APIs.


You can also use the .env file format at the root of the project to set your environment variables only once for all projects in the .NET samples repository. Just copy the sample.env file, and then fill out the information that you got from the Media Services API Access page in the Azure portal or from the Azure CLI. Rename the sample.env file to just .env to use it across all projects.

The .gitignore file is already configured to prevent publishing this file into your forked repository.

The sample performs the following actions:

  1. Creates a Transform (first, checks if the specified Transform exists).
  2. Creates an output Asset that is used as the encoding Job's output.
  3. Creates the Job's input that is based on an HTTPS URL.
  4. Submits the encoding Job using the input and output that was created earlier.
  5. Checks the Job's status.
  6. Creates a Streaming Locator.
  7. Builds streaming URLs.

For explanations about what each function in the sample does, examine the code and look at the comments in this source file.

Run the sample app

When you run the app, URLs that can be used to playback the video using different protocols are displayed.

  1. Open AMSV3Quickstarts in VSCode.
  2. Press Ctrl+F5 to run the EncodeAndStreamFiles application with .NET. This may take a few minutes.
  3. The app will output three URLs. You will use these URLs to test the stream in the next step.

Screenshot of the output from the EncodeAndStreamFiles app in Visual Studio showing three streaming URLs for use in the Azure Media Player.

In the sample's source code, you can see how the URL is built. To build it, you need to concatenate the streaming endpoint's host name and the streaming locator path.

Test with Azure Media Player

To test the stream, this article uses Azure Media Player.


If a player is hosted on an https site, make sure to update the URL to "https".

  1. Open a web browser and navigate to https://aka.ms/azuremediaplayer/.

  2. In the URL: box, paste one of the streaming URL values you got when you ran the application.

    You can paste the URL in HLS, Dash, or Smooth format and Azure Media Player will switch to an appropriate streaming protocol for playback on your device automatically.

  3. Press Update Player. This should start playing the video file in the repository.

Azure Media Player can be used for testing but should not be used in a production environment.

Clean up resources

If you no longer need any of the resources in your resource group, including the Media Services and storage accounts you created for this tutorial, delete the resource group.

Execute the following CLI command:

az group delete --name amsResourceGroup

Examine the code

For explanations about what each function in the sample does, examine the code and look at the comments in this source file.

The upload, encode, and stream files tutorial gives you a more advanced streaming example with detailed explanations.

Job error codes

See Error codes.


The Azure Media Services v3 SDKs are not thread-safe. When working with multi-threaded application, you should generate a new AzureMediaServicesClient object per thread.

Next steps