Serving Video Content from Azure Blob Storage

我与影子孤独终老i 提交于 2019-11-30 05:14:22

it was not clear for me from @smarx's answer how to set that for my blob container - but after some googling i found the code below. Just execute it in LINQPad, and video will start streaming:

var storageAccount = CloudStorageAccount.Parse("AccountName=<accountName>;AccountKey=<accountKeyBase64>;DefaultEndpointsProtocol=http");
var blobClient = storageAccount.CreateCloudBlobClient();

// Get the current service properties
var serviceProperties = blobClient.GetServiceProperties();

// Set the default service version to 2011-08-18 (or a higher version like 2012-03-01)
serviceProperties.DefaultServiceVersion = "2011-08-18";

// Save the updated service properties
blobClient.SetServiceProperties(serviceProperties);

You may try setting the default version for your storage account to 2011-08-18: http://blogs.msdn.com/b/windowsazurestorage/archive/2011/09/15/windows-azure-blobs-improved-http-headers-for-resume-on-download-and-a-change-in-if-match-conditions.aspx. It improves a couple things around range requests (probably what progressive download in your browser is doing). I haven't heard anything specific about video playback, but it can't hurt to try. :-)

I tried playing a very small MP4 encoded blob directly from HTML5 video element with control enabled, i could use the control to scroll back and forth my video.

What is the size of your video content? Also you can use Fiddler to check the HTTP Headers to verify if they are expected or does they match exactly same when you use the same blob from S3 bucket?

If you can share your blob link, i can give a quick try and see what could be the issue.

You can do it via Powershell. Here is an example for Azures ARM (not classic, but you can convert it easily).

Select-AzureRmSubscription -SubscriptionName "subscription" $Name = 'storageaccountname' $resourcegroup = 'resourcegroup'

$sp = New-Object -TypeName Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties 

$sp.DefaultServiceVersion = "2017-04-17" $key = (Get-AzureRMStorageAccountKey -StorageAccountName $Name
-ResourceGroupName $resourcegroup).Value[1]

$context = New-AzureStorageContext -StorageAccountName $Name
-StorageAccountKey $key

$blobClient = $context.StorageAccount.Create

For anyone coming here from google:

Azure has two types of storage accounts: StorageV1/V2 (default option selected when making new account) and BlobStorage.

While the StorageV2 option may have more features, it does not support partial content requests, meaning Chrome will not allow video seeking.

You can identify the type of storage you have in the Azure Portal by navigating to your Storage Account > Properties > Account Type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!