Search code examples
azuremedia-playermp4

On-demand viewing of MP4 files from Azure Storage with Azure Media Player


I am working on a school project and using my MSDN subscription for Azure access. I have written a program that uploads MP4 recordings (video surveillance) from a private network to Azure storage on a scheduled basis.

I want to be able to view these MP4 files using the Azure Media Player. I will be the only one using this stream and it would only be on a very infrequent basis (while away on vacation). I played around with the Azure Media Services a bit and it seemed like the only way I could get an "endpoint" for the media player was to open a live streaming channel. Once I did that it gave me an endpoint which I put in the player and it played my video as expected. I turned in my project proposal to my professor based on this prototype and got it approved as my semester project (40% of my grade).

To my surprise two days later I got an email alert saying that my Azure account had shut down automatically due to my exceeding the $50/mth allocation. I was surprised since the files I uploaded amounted to only 5MB and I only downloaded them twice during my proof of concept work.

While reviewing my billing details it appears all these charges came from the media services channel and it appears to based on the time the channel is "alive". 43 hours of this pretty much ate up my whole allotment for the month.

Here are my questions (keeping in mind I am a decent C# developer but completely green about all things Azure):

1) Am I going about this the right way? Do I need a live streaming channel to use the Azure Media Player?

2) If yes to the above, is there a way I can start/stop the live streaming service from code? In this way could I send a command to Azure to wake up the channel when viewing is needed then shut down when complete?

3) Is there some other html5 based media player I could use against Azure file storage so I bypass the live streaming channel and associated costs?

Thanks for any help. When I called Microsoft support all they could do was explain the billing to me and steered me here for technical support.


Solution

  • Based on your project descriptions you already have files encoded to mp4 and uploaded to Azure Media Services. You don't need to create streaming endpoint and start live channel to playback your files. You need instruct system to generate playback url which will accesible for you during defined period of time and use this url in player.

    Example of code:

            IAsset asset =_mediaContext.Assets.Where(c=>c.Name="Your MP4 Asset").First();
    
            IAccessPolicy accessPolicy = _mediaContext.AccessPolicies.Create("Read15Min", TimeSpan.FromMinutes(15), AccessPermissions.Read);           
    
            ILocator locator = _mediaContext.Locators.CreateLocator("ReadOnlyLocator", LocatorType.Sas, asset, accessPolicy, startTime: null);
    
            var uribuilder = new UriBuilder(locator.Path);
            uribuilder.Path += "/" + asset.AssetFiles.First().Name;
            var fileUri = uribuilder.ToString();
    

    To test if it is actually working simply go to http://aka.ms/azuremediaplayer and paste value of fileUri to Url input textbox.

    If you serious about security i would recommend to read about Content Protection in Azure Media Services and dynamically encrypt content to use token authentication. In my blog post I showed how you can integrate Azure AD authentication in your ASP.NET MVC app with Azure Media Services to protect your content.