Soon after handing over Traverous app to beta testers and early adopters, the first feedback we heard was “Videos are too sloow”…

TLDR;

You don’t necessarily need to be competing with YouTube to feel the need to deploy your own Video On-Demand solution. Apps and websites, who have something to do with user created videos often come to the point where they have to deploy their own VOD streaming solution. And if you are a startup, it’s just adds an equal amount to the tension you are already handling.

In this story, I’ve tried my best to make it simple and effortless to deploy your own VOD solution. I explain DASH, some existing Cloud solutions available to leverage DASH standard for Video On-Demand, and then I explain the procedure of deploying a VOD solution on Azure Media Services. Because videos are too sloow.

The code for deploying VOD on Azure with NodeJs is available on GitHub under project name Gale Crater.

What is DASH?

Dynamic Adaptive Streaming over HTTP (DASH) is an industry standard used for streaming high quality videos on Internet using conventional HTTP servers. In simple words it is the set of rules that enable the video player in your browser (or on your device) to switch to appropriate video quality according to your choice or Internet speed. Before DASH, Microsoft used it’s own streaming protocol called Smooth Streaming. While Apple still uses HLS mostly.

Streaming Media’s DASH explaination:

HTTP-based adaptive streaming technologies have two components: the encoded Audio/Video (files) streams themselves and manifest files that identify the streams for the player and contain their URL addresses. For DASH, the actual Audio/Video streams are called the Media Presentation, while the manifest file is called the Media Presentation Description (MPD).

Simple DASH architecture by Chih-Hsiang

Video On-Demand on the Cloud

Multiple cloud providers provide Video On-Demand solutions. Video On-Demand is just like YouTube. Whenever you choose to watch some videos or any specific video, you can open that YouTube video and start watching the content you like.

The top Cloud Providers provide the services for deploying VOD solutions using Encoding, Transcoding and Streaming services.

At a high level, Azure Media Services leverages the power of Azure Storage, CDNs and Transcoding service to provide On-Demand and Live-streaming services.

Azure Media Services a high level view

At a “high” level, Amazon Elastic Transcoder has the same architecture.

There are multiple independent Encoding and Transcoding services available too that automate all this process for you through simple APIs. (If you provide some such service, reach out to me. I will add it here).

Deploy Video On-Demand with Azure Media Services (AMS)

The detailed process of establishing VOD service on all cloud services is different. Azure provides On-Demand and Live Streaming services through Azure Media Services. I recommend you go through Get started with delivering content on demand by using the Azure portal to manually create a Media Services account, upload a video file, transcode it and play it in a DASH supported player. Then follow the rest of this guide. The accompanying project uses Node.Js to request to AMS’s REST APIs to automate our video transcoding jobs. If you have just basic programming knowledge, I think you can understand the code. Below, I’d walk through the process need to be followed for automation of Video On-Demand on Azure Media Services.

Prerequisites

Microsoft Azure account

Understanding of REST APIs

Start Streaming endpoint

Through Azure Portal, create a Azure Media Services (AMS) account if you haven’t already. Associate an Azure Active Directory account with it and start the streaming endpoint (under your media services account > Streaming endpoints > default > Start).

Configure Keys & Variables

You would need following keys/variables to access Media Services through REST APIs

TenantID

As answered on MSDN Social: Launch a cloud shell in the portal (click on the “>_” icon in the upper right toolbar). Wait for the Bash Shell to start and type in “az account show”.

2. AzureADSTSEndpoint

https://login.microsoftonline.com/<TENANT_ID>/oauth2/token

3. RESTAPIEndpoint

Go to: Your Media Services > Overview > copy REST API endpoint

4. ClientID

Go to: Your Media Services account > API Access > Connect to Media Services API with service principal > Manage application > copy Application ID.

5. ClientSecret

Go to: Your Media Service account > API Access > Connect to Media Services API with service principal > Manage application > Settings > Add a Password with description, expiry and value > Copy password’s hash.

Get Access Token

From Azure Active Directory

AMS uses Azure Active Directory for authentication of all requests. All the subsequent requests would use this access token.

Create a Access Policy for Upload

Get Access Policy for with Write/Upload rights from Media Services

We need to put in place an Access Policy to be able to upload files to Media Services. Access policy determines the permissions one has to Media Services. An access policy cannot be deleted if it has a Locator associated with it. You can reuse same Access Policy for multiple operations. Usually Access Policy has types: Read, Write, Delete, List. When you create an Access Policy, you also specify DurationInMinutes . This determines the maximum expiration time of a Locator associated with the Access Policy. More on Locators below.

Create Asset

Create Media Service Asset to contain files

Media Services uses Azure Storage for storing uploaded files. An asset can contain multiple files. Asset is more like an Azure Storage container. When you create an asset in Media Services, you can also find a matching container in your Azure Storage account linked with Media Services account. The files uploaded to an asset now become available for processing or streaming. You can also encrypt your assets.

Create Uploading Locator

Locator for uploading files

A locator serves as a pointer to the asset with an expiration time set. You can only create a maximum of 5 locators to the same asset. It would help us in uploading our file into the asset.

Create Metadata in the Asset

After file upload, we need to create metadata for the asset. It’s just simple GET request to certain API URL.

Encode source file into set of Adaptive Bitrate MP4 files

When you encode the your source file through Media Services, you get a set of adaptive bitrate mp4 files. These are the files, along with few manifest files that a DASH/HLS/Smooth Streaming supported player can use to adapt to appropriate quality according to network speed or user’s choice.

Group of video and encoding information files

Get encoded Asset

Get reference to the encoded asset container

Once encoding job starts, you get output asset URI in response. With GaleCrater, you can manage the job state. Once it’s complete (job status: 3), you can get the reference to the resulted asset.

Create a Read Access Policy

We already created an access policy for our application with upload/write permissions in order to upload a file. But we need a read access policy to read the file. At this point, we would create one.

Create Streaming Locator

We’d need a locator to our “encoded asset” to be able to stream the video.

Stream

And now comes the output of more than a week of effort. The streaming locator retrieved from Azure would contain a key Path which is the first part of the URL. Append it with the filename that you uploaded (without extension) and append again with .ism/Manifest(format=mpd-time-csf) for DASH streaming. HLS and Smooth Streaming are also supported with small change in the URL. I transcoded the video to get following streaming url:

http://travmediaservice-euwe.streaming.media.azure.net/b4d3703c-8773-4e76-9054-67e3dcd0aa34/gilgitqandeel-original.ism/manifest(format=mpd-time-csf)

Since we are testing, the above URL may or may not be working. Go to DASH Industry Form’s Reference Client, paste the above URL in input and click load. The player would start playing the video and adapt to network change.

End Note

I have compiled this guide and we are releasing code for Node.JS library for straight away setup of On Demand Streaming for your product. Our aim is that a passionate student, a hobbyist or even an engineer working on a product in his/her dorm doesn’t have to go through the hectic process of going through recursive links in guides and docs to find information. Because it really sloows down the process. I hope it would help you.

If you want to know more about Traverous, it’s an automated Travel Diary app and a social community of travelers.

Happy hacking!