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.

Overview

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.

Setup

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";
				unlink(TOKEN_STORAGE);
				$this->requestToken();
			}
		} else {
			echo 'Get new token from API'."\n";
			$arrData = array(
				'grant_type=client_credentials',
				'client_id='.CLIENT_ID,
				'client_secret='.urlencode(ACCESS_KEY),
				'scope=urn%3aWindowsAzureMediaServices'
			);
			$arrHeader = array(
				'Content-length:'.strlen($this->generateData($arrData))
			);

			$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);
			curl_close($ch);

			$arrToken = json_decode($data);
			if (isset($arrToken->error)){
				print_r($arrToken);
				die();
			}
			$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.

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

  1. Shraddha

    With reference to example at http://cloudstory.in/2012/02/windows-azure-storage-for-php-developers/ 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.

    Reply

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>