Getting Started with Azure Media Services
Tags: azure, azuremediaservices, cloudservices, microsoft
Published: 2024-03-18 13:47:28

## Setting up Azure Media Services and AMP on your project

Hi folks, in today's blog, we'll go over how to set up media services on the Azure portal. Azure media services power your streaming services, which include content streaming, encoding and transcoding, content protection, and digital rights management (DRM).

> Azure Media Services (AMS) is a cloud-based platform offered by Microsoft Azure that allows you to create, manage, and distribute media content at large scale. Its primary goal is to make it easier to create, process, deliver, and monetize a variety of media content, such as video, audio, and streaming services.

Azure Media Services enable you to build media applications using low-latency live streaming, batch encoding, content-protection/DRM, and deliver streaming content to millions of viewers on any device.

To setup Azure Media Services (AMS), there are basically six steps.

- 1. - Step 1: Create Azure Media Services (AMS)
- 2. - Step 2: Manage (Upload) Assets
- 3. - Step 3: Add Job
- 4. - Step 4: Set/add content protection policy [optional if no DRM]
- 5. - Step 5: Add streaming locator
- 6. - Step 6: Use the generated streaming URLs to stream video

## Step 1: Create Azure Media Services

This is the first step in creating the necessary resource that is required to setup Azure Media Services (AMS) for our project. It's fine if you have an existing resource group or else go head and create a resource.

> Create a Resource Group


![Microsoft Azure Home Page] (https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7rp38yp09myqjjkvece0.png)

After creating a resource group, now is the time to create Azure Media Services. To do that, simply go over the azure portal and search media services on the search bar. And select media services from the results filtered.

> Create Azure Media Services Resource


![Search result for Azure Media Services](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bsr46ug5zaaxqseeihq7.png)

At this stage there is a lot to configure as we have to specify the media service account name, location and storage account to name a few. Below is shown the complete configuration setup.

> - Specify resource group that you created earlier. [use existing if there is]
> - Specify media service account name
> - Choose location
> - Create new storage account [most of the time it is v2 general purpose]
> - Create new user assigned managed identity


![Create media service account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bnwzmj78zyvwxdrkn2od.png)


![Create media service storage account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i6q9rfcd40j9olsd5cnz.png)

Now we will click on the 'Review + create' button to create our media service account.

![Review and Creating](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xs0jjcu9vjwsyubka7et.png)

At this point, Azure will validate the required fields, and if we have filled out all of the fields correctly, we will be able to create our media service account instantly.

Upon the successful deployment of our media service account, it is time to move on managing our assets on the media service account.

![Media Service account created successfully](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dacrp31ln3gm5aqyliiw.png)

Click on the 'Go to resource' as shown on the image above and head over to the media service page. As you can see, we don't have any asset to consume or process, thus let's upload the assets we are going to work with.

![Media Service Account Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/upow3snmtqn6p1v5bic1.png)

## Step 2: Manage Assets

This step focuses on managing assets by uploading files or using external links in order to prepare the assets (audio, video, etc.). In this tutorial we focus on managing video assets.
To upload assets to our media service account, go to the left side bar and select 'Assets' link.

![Assets Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w3uqy5yc5hkbumvhffkv.png)

The Assets Page is empty as it is our first time working with it so, go and click Upload to upload our video.

![Uploading new assets](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qb9le254bdgyr3isuxk.png)

This stage is pretty straight forward. Select the file you want to upload and then click on 'I agree, upload and close'. It will take some time depending up on how large your file is.

![Asset uploaded successfully](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/anfudls3f3mvlrkfyu90.png)

Now our video is uploaded to the blob storage of our media service storage account which we create earlier.

## Step 3: Add Job

Welcome to step 3 champ 🏆I guess you are following along, and everything is going well for you. This step is very crucial as it is the main part of configuring the media service processing that includes encoding.

Select the checkbox of the asset you uploaded and click on 'Add Job'.

![Create a Transform](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r252k33nhqvph8pelxqi.png)

To clarify things here, there are two key words in this step. Transform and Job. A "Job" refers to a task or process that is performed on media assets using the Azure Media Services platform. These jobs can encompass a variety of tasks such as encoding, transcoding, packaging, encrypting, analyzing, or transforming media files. Whereas "Transform" refers to a set of predefined configurations or presets that define how media content should be processed or transformed. This can include specifications for encoding settings, transcoding formats, bitrate, resolution, audio settings, and more.

Transforms allow users to apply consistent processing settings across multiple media assets, simplifying the workflow and ensuring uniform output quality.

When you create a job in Azure Media Services, you typically associate it with a transform, specifying which transform configuration to apply to the media assets being processed. This allows you to efficiently manage and automate the processing of your media content according to predefined settings.

> - Create Transform
> - Specify transform name
> - Choose transform type
> - Choose built-in preset name [choose adaptive streaming to get multi bitrate]

![Create a Job](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jayf78j6d5nfgdvwdb33.png)

> - Configure Job
> - Specify output name
> - Choose asset storage account [ leave it as it is if there is only one storage account ]
> - Specify job name
> - Specify job priority [ mostly leave it on 'Normal' but it depends on your processing type ]
> - Select create

## Step 4: Set/add Content Protection Policy

Content Protection Policy is a set of rules and configurations that define how your media content is protected against unauthorized access and piracy. These policies are applied to your media assets to ensure that they are securely delivered to only authorized users or devices.

To setup a content protection policy, click on 'Content key policies' on the left side bar.

![Content key policies page and add content key policy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s4vv4h63oqh22buhjtow.png)

> Specify content key policy name

![create content key policy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z1ibkmqu6sfzuk2n0c3n.png)

> - Add Digital rights management (DRM)
> - Add Google Widevine, Apple FairPlay, or Microsoft PlayReady [you can include one or more DRM]

we will use Microsoft PlayReady DRM policy in our case.

![create DRM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/niu31aqwfc6rrvtmu5nk.png)

> Add AES clear key to protect your content with AES-128 encryption [optional configuration]

Setting up the AES clear key encryption is the same approach as setting up DRM.

![Add a PlayReady policy option](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kvz9ny3q8ryo4pyvj775.png)

> - Specify policy name [ optional ]
> - Select Yes for use token restriction
> - Select JWT or SWT for token type
> - Specify issuer [ eg. myIssuer ]
> - Specify audience [ eg. myAudience ]

![setting up license settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4chjggqmv5opr166bly.png)

![setting up output protection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fw1ikf1csl8xmx1nxdda.png)

> Click Add and finish creating content key policy

## Step 5: Add Streaming Locator

Now, it is time to add a streaming locator. A streaming locator is a resource that provides access to streaming endpoints for your media content. It essentially serves as a pointer or URL that clients can use to access the media content securely over the internet.

> - Go to the uploaded media
> - Add new streaming locator
> - Specify name

![Add Streaming Locator](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3z59zr1mqx5bdupbrk2d.png)

> - Choose Streaming policy [ there are different policies ]
> - Choose Predefined_MultiDrmCencStreaming and MutltiDrmStreaming for encrypted videos
> - Choose Predefined ClearStreamingOnly and DownloadAndClearStreaming for downloadable unencrypted videos
> - Choose content key policy
> - Choose add and finish streaming locator

One thing to notice here is that the default streaming endpoint is inactive by default at the time of creation. So, we need to manually start it to begin streaming. After the endpoint is turned on or started the billing process also starts counting up.

![streaming endpoints page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u407tx8f11uafocxakgs.png)

![starting the default streaming endpoint](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aq33gjq6bifsfnpvj3yj.png)

At this stage, processing the media i.e. encoding, encrypting etc. has been completed successfully. What remains would be getting the streaming URLs to stream our video. This would lead us to the last step on setting up Azure Media Services to stream our video.

## Step 6: Use the generated streaming URLs to stream video

All is done now! we have our video processed for us to be consumed and streamed. This step guides you to get the streaming URLs of the video asset we have been working with till now. After getting the streaming URL, one can use the URL to stream the video on the Azure Media Player.

> Go to the media output file

![Processed video asset](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gm4uj1rwq7bbbvdkdqj.png)

![Video Outupt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ya0pyroy1ncdpw94fxva.png)

> Click view locator Find the streaming and download URLs [You can also find the streaming URLs on the Playback section]

![Finding the Streaming URLs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3wenzm1rzu16229xox2q.png)

> Copy it to use it on the web page you want your video streamed.

![Streaming URLs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xb66hky8f9la9xyqnne.png)

You can play the video on the embedded Azure Media Player inside Azure.

🎉Congrats!! 🎉you have made it to the end but not the very end 😁. On the next blog, I will show you how to add Azure Media Services Video to a Web Page/ Using AMS video on your project.
Stay tuned and let me know what you think down in the comment section!! 😉

## References

[1. Content Key Policies in Media Services - Azure | Microsoft Learn](https://medium.com/r/?url=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Fazure%2Fmedia-services%2Flatest%2Fdrm-content-key-policy-concept)
[2. Transforms and Jobs in Media Services | Microsoft Learn](https://medium.com/r/?url=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Fazure%2Fmedia-services%2Flatest%2Ftransform-jobs-concept)
[3. Streaming Policies in Azure Media Services | Microsoft Learn](https://medium.com/r/?url=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Fazure%2Fmedia-services%2Flatest%2Fstream-streaming-policy-concept)
[4. Encoding video and audio with Media Services | Microsoft Learn](https://medium.com/r/?url=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Fazure%2Fmedia-services%2Flatest%2Fencode-concept)

Updated Notice: [Azure Media Services is being retired on 30 June 2024](https://medium.com/r/?url=https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fupdates%2Fretirement-notice-azure-media-services-is-being-retired-on-30-june-2024%2F)