Dan Nick
Dan Nick

Reputation: 426

Video does not play after Encode

I upload a video to azure, create an asset, and encode the video. When the encoding is finished I get four files in an asset folder (.ism, .mp4, .xml, .xml) and the links to each source. When I try to play the .mp4 file in a video player nothing happens. However when I download the .mp4 file it works fine.

<video id="video1" src="https://123media.blob.core.windows.net/asset-bf389cc4-8454-410a-9492-7acab59b2d25/Wildlife_H264_4500kbps_AAC_und_ch2_128kbps.mp4" autoplay="autoplay" height="400" width="600" />

        CloudStorageAccount storageAccount1 = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
        CloudBlobClient cloudBlobClient1 = storageAccount1.CreateCloudBlobClient();
        var context = new CloudMediaContext("123media", "###############################");
        var CreateAsset = context.Assets.Create(Path.GetFileNameWithoutExtension(fileName), AssetCreationOptions.None);
        var assetFile = CreateAsset.AssetFiles.Create(fileName);

        IAccessPolicy writePolicy = context.AccessPolicies.Create("Policy For Copying", TimeSpan.FromMinutes(30), AccessPermissions.Write | AccessPermissions.List);
        ILocator assetLocator = context.Locators.CreateSasLocator(CreateAsset, writePolicy, DateTime.UtcNow.AddMinutes(-5));
        string assetContainerName = (new Uri(assetLocator.Path)).Segments[1];
        CloudBlobContainer assetContainer = cloudBlobClient1.GetContainerReference(assetContainerName);
        CloudBlockBlob assetBlob = assetContainer.GetBlockBlobReference(blobName);
        assetBlob.StartCopyFromBlob(blob);

        var inputAsset = context.Assets.Where(a => a.Id == CreateAsset.Id).FirstOrDefault();
        if (inputAsset == null)
            throw new ArgumentException("Could not find assetId: " + CreateAsset.Id);
        var encodingPreset = "H264 Broadband 720p"; // <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj129582.aspx#H264Encoding">http://msdn.microsoft.com/en-us/library/windowsazure/jj129582.aspx#H264Encoding</a>
        IJob job = context.Jobs.Create("Encoding " + inputAsset.Name + " to " + encodingPreset);
        IMediaProcessor latestWameMediaProcessor = (from p in context.MediaProcessors where p.Name == "Windows Azure Media Encoder" select p).ToList().OrderBy(wame => new Version(wame.Version)).LastOrDefault();
        ITask encodeTask = job.Tasks.AddNew("Encoding", latestWameMediaProcessor, encodingPreset, TaskOptions.None);
        encodeTask.InputAssets.Add(inputAsset);
        encodeTask.OutputAssets.AddNew(inputAsset.Name + " as " + encodingPreset, AssetCreationOptions.None);
        job.Submit();
        job.GetExecutionProgressTask(CancellationToken.None).Wait();

Upvotes: 0

Views: 497

Answers (3)

Varun Rathore
Varun Rathore

Reputation: 7898

One reason why you might not be able to play the video will be, you haven't added a Streaming Endpoint on your media services account. Assign at least one unit to be able to stream your video online. That did the trick for me. Find it here.

enter image description here

Also, follow the blog by MingFei Yan. Very useful when starting with Azure Media Services.

Upvotes: 1

astaykov
astaykov

Reputation: 30903

There are couple of things with Azure Media Services.

First of all, although Azure Media Services works directly with Azure Storage, I strongly advice you to not work directly with the underlying storage (although you technically can). The reason is - you will very fast loose control what is available to public, and what not. Even more - you can potentially break the Assets - Blobs links and cause inconsistency in your Media Service.

Second, the correct way to play an MP4 result into Video element is by providing the Full path to the MP4 assest with a Shared Access Signature Locator. The containers and blobs which Media Services is using are marked as private and no public access is allowed. So, you need a locator. And when you want to just see the result in a Video element, you need a Shared Access Signature locator that points to the MP4. This will be progressive download video play, but it will play.

Last, but not least, never forget (from docu):

There may be a 30-40 second delay after a Locator is created to when it is available for use. This issue applies to both SAS URL and OnDemandOrigin locators.

So you need a logic to manage your locators. As far as I remember, and if it is still the case, there is limit of the number of locators (or access policies) you can create per asset.

Upvotes: 0

Alexey Shcherbak
Alexey Shcherbak

Reputation: 3454

If your asset publicly available by that URL - try to add type='video/mp4' to the video tag.

Side note - also you need to 'publish' video so it'll be stream-able via shared 'encoding units' - your .ism file indicates you've created some kind of Streaming public asset (Smooth one I guess).

Keep in mind that streaming is not yet fully supported in all browsers (MPEG DASH is HTML5 streaming format) and for other streaming formats (Smooth or Apple HLS) you'll need to use Silverlight \ Flash implementations.

Upvotes: 0

Related Questions