1

I have an azure media services account with some uploaded videos, but these videos only play on the browser with some additional parameters like these (?sv=2017-04-17&sr=c&sig=QMSr...) something like authentication keys. I want a generic permanent progressive video URL that can be played anytime, I tried to use the azure media player with my video URLs with .ism/manifest and .mp4 but both couldn't be played exp:

https://<MY_BLOBSTORAGE_ACCOUNT>.blob.core.windows.net/<Asset-ID>/Video_FILE_NAME>.ism/manifest

https://<MY_BLOBSTORAGE_ACCOUNT>.blob.core.windows.net/<Asset-ID>/<Video_FILE_NAME>_1280x720_AACAudio.mp4

I have tried the player from this official microsoft documentation: http://amp.azure.net/libs/amp/latest/docs/index.html#full-setup-of-azure-media-player

Also note that the Azure Media Services V3 documentation & the community of the ams itself is very poor and weak in terms of explaining the steps for programmatically getting the video urls for the player.

Mohamad Al Asmar
  • 1,107
  • 1
  • 16
  • 35

3 Answers3

2

With AMS v3, you will have to create a streaming locator, and you can use a prebuilt streaming policy. There are policies for - streaming only - streaming and download - download only

With the download policy, you will get a URL for each blobs in the asset. For example : https://myaccount-uswc.streaming.media.azure.net/1544fcae-a248-4f53-b653-cd02074b04b6/video_848x480_2200.mp4

With a streaming policy (recommended), you will get a DASH, HLS and Smooth URL like: https://myaccount-uswc.streaming.media.azure.net/0eef6f88-47c6-4662-9111-60305d7c1000/video.ism/manifest(format=mpd-time-csf).mpd

1

It appears that you're mixing progressive download and streaming. I wrote a blog post on the differences as it relates to Azure Media Services at https://blogs.msdn.microsoft.com/randomnumber/2016/03/23/progressive-download-and-streaming-differences-with-azure-media-services/. If you encoded the video into an adaptive bitrate MP4 set then more than likely you'll want to stream the video instead of using progressive download on a single MP4. This might help with the streaming side: https://learn.microsoft.com/en-us/azure/media-services/latest/dynamic-packaging-overview

David Bristol
  • 621
  • 3
  • 6
1

I found the solution with help of a friend, after creating the streaming locator, I have to make sure that the streaming endpoint is running and then get build URLs by looping over paths which I need to get using StreamingLocators.ListPathsAsync, below is the code snippet.

        private async Task<StreamingLocator> CreateStreamingLocatorAsync(
            IAzureMediaServicesClient client,
            string resourceGroup,
            string accountName,
            string assetName,
            string locatorName)
        {
            StreamingLocator locator = await client.StreamingLocators.CreateAsync(
                resourceGroup,
                accountName,
                locatorName,
                new StreamingLocator
                {
                    AssetName = assetName,
                    StreamingPolicyName = PredefinedStreamingPolicy.ClearStreamingOnly
                });

            return locator;
        }

        private async Task<IList<string>> GetStreamingUrlsAsync(
            IAzureMediaServicesClient client,
            string resourceGroupName,
            string accountName,
            String locatorName)
        {
            const string DefaultStreamingEndpointName = "default";

            IList<string> streamingUrls = new List<string>();

            StreamingEndpoint streamingEndpoint = await client.StreamingEndpoints.GetAsync(resourceGroupName, accountName, DefaultStreamingEndpointName);

            if (streamingEndpoint != null)
            {
                if (streamingEndpoint.ResourceState != StreamingEndpointResourceState.Running)
                {
                    await client.StreamingEndpoints.StartAsync(resourceGroupName, accountName, DefaultStreamingEndpointName);
                }
            }

            ListPathsResponse paths = await client.StreamingLocators.ListPathsAsync(resourceGroupName, accountName, locatorName);

            foreach (StreamingPath path in paths.StreamingPaths)
            {
                UriBuilder uriBuilder = new UriBuilder();
                uriBuilder.Scheme = "https";
                uriBuilder.Host = streamingEndpoint.HostName;

                uriBuilder.Path = path.Paths[0];
                streamingUrls.Add(uriBuilder.ToString());
            }

            return streamingUrls;
        }

and in my service method I do the below:

StreamingLocator locator = await CreateStreamingLocatorAsync(client,
config.ResourceGroup, config.AccountName, outputAsset.Name, locatorName);

IList<string> streamingUrls = await GetStreamingUrlsAsync(client, config.ResourceGroup, config.AccountName, locator.Name);
foreach (var url in streamingUrls)
   {
       urls.Add(url);
       Console.WriteLine(url);
   }
myModel.StreamingUrls = urls;
Mohamad Al Asmar
  • 1,107
  • 1
  • 16
  • 35