Microsoft Azure Media Services – How to encode in the Azure Cloud – Part 1

I open a serie of posts which will talk about this solution. Microsoft announced at the end of spring the preview of Windows Azure Media Services. WAMS form an extensible media platform that integrates the best of the Microsoft Media Platform and third-party media components in Windows Azure.


WAMS can transform movie in differents formats and codecs :

  • Supported video and audio codecs:
    • H.264 High, Main and Baseline Profiles
    • AAC-LC
    • HE-AAC
    • VC-1 (Windows Media Video 9) Simple, Main and Advanced Profiles
    • Windows Media Audio Standard
    • Windows Media Audio Professional
  • Supported format conversions:
    • ISO MP4 (.mp4) to Smooth Streaming File Format (PIFF 1.3) (.ismv; .isma)
    • Smooth Streaming File Format (PIFF) to Apple HTTP Live Streaming (.msu8, .ts)

For the moment, you can only make VoD video.
It is already possible to encrypt your content (via PlayReady DRM). You can manage it via .NET or REST API. I’m not a .NET developer, so I will try the solution via API. My code side will be in PHP.


First of all, you need to setup your account to use WAMS. Currently, the setup is only possible via Powershell, but it will change via the Azure portal. For this step, you need a Windows, but after you can use other OS.

To connect to Media services, you need two things : 1) an access token provided by Windows Azure Access Control Services (ACS) and 2) the URI of Media Services itself. To get the token, you make a OAuth request with the parameter you get when you setup your account : the access key and the client ID. Different libraries are available in different langage to make this kind of request, for me, I create a simple PHP method to manage it.

class Rest{

	protected $strUrl;

	protected $strToken;

	protected $strBody;

	public function requestToken(){
		if (!file_exists(TOKEN_STORAGE)){
			echo 'Get Token from storage'."\n";
			$data = file_get_contents(TOKEN_STORAGE);
			$arrToken = json_decode($data);
			if ((filemtime(TOKEN_STORAGE) + $arrToken->expires_in) > time()) {
				$this->strToken = $arrToken->access_token;
			} else {
				echo 'Token expired'."\n";
		} else {
			echo 'Get new token from API'."\n";
			$arrData = array(
			$arrHeader = array(

			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, TOKEN_URL);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $this->generateData($arrData));
			curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeader);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			$data = curl_exec($ch);

			$arrToken = json_decode($data);
			if (isset($arrToken->error)){
			$this->strToken = $arrToken->access_token;
			file_put_contents(TOKEN_STORAGE, $data);
			echo 'Token save in storage'."\n";
	     return $this->strToken;

The AMS response will contains the token. If you make many calls, I suggest to cache the access token, the expires_in value and the timestamp of the request to avoid unnecessary calls.

Now, we have a token to access, we can play with the Azure Media Services. We will see it in next posts.

1 thought on “Microsoft Azure Media Services – How to encode in the Azure Cloud – Part 1

  1. Shraddha

    With reference to example at Why does require_once ‘Microsoft/WindowsAzure/Storage/Blob.php’; give an error saying Unable to access Microsoft/WindowsAzure/Storage/Blob.php. But if I try to locate Blob.php in the folder structure it is located at pear\WindowsAzure\Blob\Models\Blob.php. If I change this path to the correct one I get this error Class ‘Microsoft_WindowsAzure_Storage_Blob’ not found.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.