Windows Azure offers an easy and modern way to work with media files. With Azure Media Services you can upload video files, encode them and offer them for streaming clients. A great way to use multimedia content in your webs and apps!
For example Azure Media Services have been used in the Olympic Games 2012 in London for delivering more than 2,300 hours of live and HD content to more than 20 countries for multiple Olympics broadcasters, see Windows Azure Media Services Case Study.
In this article I will show you how easy Azure media services can be used, not too much in detail but showing the process and how to use the streaming content in your web apps.
Create your media service
In Windows Azure portal create a new media service in Media Services/Create. In App Services choose a name, region and if your want to use a new or existing storage account for storing the BLOBs.
A video file consits of a container (which wraps the audio and video codecs, but doesn't contain the raw data itself), a video codec and the audio codec . When using good codecs, you get smaller resulting video files without any quality loss.
Today mainly these formats are used in Internet, see MP4 Video Encoding:
- The MP4 format, with H264 video and AAC audio.
- The WebM format, with VP8 video and Vorbis audio.
- The FLV format, with H263 video and MP3 audio.
Which format works where?
- MP4 works on devices, on browsers in Flash and on half the browsers in HTML5.
- WebM only works on half the browsers in HTML5.
- FLV only works on browsers in Flash.
In many cases the HTML5 video is first choice, supported by most modern browsers, like Internet Explorer 9+, Firefox, Opera, Chrome, and Safari. This is the HTML5 code:
Currently, there are 3 supported video formats for the <video> element: MP4, WebM, and Ogg.
IE supports MP4 only, Chrome and Firefox (up from v21) both support MP4, WebM and Ogg.
Safari supports MP4 only and Opera only WebM and Ogg, see HTML5 Video
In Azure find the Supported Codecs and File Types for Windows Azure Media Encoder. For exporting you can choose between wmv, wma, mp4 and the smooth streaming file formats ismv and isma.
The upload of your video files can be done in the Azure portal. Go to “content”, click “upload” and here we go!
In Uploading Media you find an overview of relevant concepts and different ways to upload your content.
Tip: Uploading only works for small video files…
Uploading large video files
If you want to upload a video file larger than 200MB the Azure portal denies the upload process, see:
Well, my demo video file “Deep-Dive-WAAD.mp4” is 263MB…
I guess, Microsoft wants to avoid problems with timeouts in the portal website.
Use the API with an app
Ok, let´s create a small app for uploading my large video file. First I create a new WPF project in Visual Studio 2013. Now we need to install the Windows Azure Media Services .NET SDK, see Windows Azure Media Services .NET SDK 3.0.0.
Run the following command in the Package Manager Console:
PM> Install-Package windowsazure.mediaservices
After we have all the necessary components in our project, we need some code from the Azure portal. We get the sample code directly from the start page of our media service.
So simply copy and paste the generated code – including my media services key – to my project, f.e. in a button click event. So my slightly adapted code looks like this:
When we run the application and start the upload the Azure portal already has the file in it´s content.
The upload on my WiFi takes some time, something like 30 minutes.
Time to switch to cable…anyway, WiFi should be good enough, it´s sunday.
Improving the uploading app
The sample code of course doesn´t have any error handling built in – that would be on your side, at least a try-catch block and a retry-logic or similiar.
Also I would like to add a simple UI so that the desktop app can be used for any Media Service and any video. So let´s improve the app somehow. This shall be the frontend:
The XAML now looks like this
Also we add the media service data in app.config with new keys “Media*”.
And finally modify the code with some improvements like load media data, file picker, center screen and with async method.
When done, the app should run like this – and display a done message when finished.
If you plan to upload a large set of files take a look in this article here: Ingesting Assets in Bulk with the Media Services SDK for .NET.
Hint: In Windows Azure Store there´s a third party solution by Aspera for high-speed transportion to Windows Azure cloud-based object storage. Aspera uses fasp transport technology which means UDP upload, which is much faster than HTTPS - if you need more that the standard speed, for example greater than 100Mbps, as well as encryption of content content before it gets uploaded, see here.
Now, when the video file is uploaded we can start working with it. As of today, the most used video formats are MP4, FLV, AVI, WebM and MOV. In Azure we can use these formats (MP4, AVI, ASF, MPEG, MPG, MOD, WMV and some more).
So, let´s encode our video in one or more formats with the “encode” button. Choose a format and confirm the name of the suggested output file “<name>-<format>” or type your own filename.
Now the encoding process is queued. You can watch the jobs and processes in “jobs”.
If you want to encode more than one task parallel, you can scale it.
By default, on-demand streaming is configured in a shared-instance model.
On-Demand Streaming reserved units provides dedicated egress capacity that can be purchased in increments of 200 Mbps, see How to Scale a Media Service.
Tip: Remember that it takes up to 20 minutes till the allocation of any new units of on-demand streaming completes!
By default every Media Services account can scale to up to 25 Encoding and 5 On-Demand Streaming Reserved Units. For more performance you need to open a support ticket.
If you plan to automate the whole video upload and encoding process have a look at the ready-to-use snippet for encoding a video programmatically in the portal:
The work to be done is to add a new task with a particullary MediaProcessor. Cool and easy to use.
Once the content is encoded, publish each version you would like to deliver.
You get an URL for the video-file, like
You can test the video file directly in the Azure portal by clicking the “play” button. Nice!
Reuse the HTML-Code
Look at the player with the IE-Developer Tools (F12). Mark the video-player and you get the code.
You see the <video> Tag containing the .mp4 video file.
The application uses an HTML5 <video> tag to handle media streaming. Of course you can use this HTML-snippet in your own apps.
When playing the video and checking with the HTTP debugging proxy Fiddler you can see the tunnel to the Azure storage. When clicking f.e. in a later positions in the video you see the range adapting.
For building apps with a robust video player, Microsoft recommends the Microsoft Media Platform Player Framework from http://playerframework.codeplex.com/.
The Player Framework can be used for Windows 8, HTML5, Silverlight, Windows Phone and other application platforms. You can define playlists and use many more features like localization and so on.
After installing Microsoft.PlayerFramework.vsix you have a bunch of Plugins on your computer, usually located in C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0\ExtensionSDKs\Microsoft.PlayerFramework\22.214.171.124 .
For samples download Microsoft.PlayerFramework.Samples.zip.
The basic usage of HTML5 Player Framework can look like this:
Creating a basic Windows 8 app with streaming video
For Windows 8 apps you need the Smooth Streaming Client SDK for Windows 8.1. This enables developers to build Windows 8.1 Store applications that consume On-Demand and Live Smooth Streaming content with PlayReady protection.
- Download the SDK here: Microsoft Smooth Streaming Client SDK for Windows 8.1 .
Attention, this SDK is only valid on Windows 8.1 with using Visual Studi 2013.
- Download Microsoft PlayReady Client SDK for Windows 8.1 Store Apps. The Microsoft PlayReady Client SDK for Windows 8.1 Store apps allows Windows 8.1 application developers to utilize Microsoft PlayReady content access technology for protecting digital content from unauthorized usage.
Find a sample here: PlayReady sample for Windows 8.1 Store apps.
Azure Media Services conclusion
With Azure Media Services it´s simple to upload audio and video files into a Windows Azure storage and to start encoding tasks as well as using the streamed multimedia content.
If you plan to use streaming in your own apps Windows Azure Media Services are right here for you!