如何使用Azure blob存储中的部分内容范围正确流式传输视频?

问题描述 投票:0回答:1

我有一个已上传到Azure Blob存储(块,存储v2)的mp4视频。我无法使用<video>标记来提供视频,而没有从视频服务器完全下载了视频(带有200个响应状态代码),因此播放没有延迟。

((更糟糕的是,尽管与我的问题不完全相关,因为我认为这更多是浏览器问题,该视频已设置为循环播放,并且每次循环都将重新下载该视频。)

我想使用部分内容范围流式传输视频,以便立即开始播放。

我已经尝试直接采购视频,为<video>标签src属性提供绝对URI;并且我还尝试通过ASP .NET Core 3.1控制器方法提供视频,返回FileStreamResult并将enableRangeProcessing参数设置为true。这是该代码:

public async Task<IActionResult> GetVideo(string videoUrl)
{
    var httpClient = new HttpClient();
    var stream = await httpClient.GetStreamAsync(videoUrl);
    return File(stream, new MediaTypeHeaderValue("video/mp4").MediaType, true);
}

似乎无论我尝试什么,都无法获得状态码为206的范围响应。我已经看到了有关使用Azure媒体服务的建议,但似乎有些矫kill过正,而且应该在不需要合并其他服务的情况下才支持它。

任何帮助/建议将不胜感激-谢谢!

c# video-streaming html5-video azure-storage-blobs asp.net-core-3.1
1个回答
0
投票

根据我的研究,如果将enableRangeProcessing参数设置为true,我们将获得范围响应。有关更多详细信息,请参阅issue

我的测试代码

public async Task<IActionResult> Video() {
            var s = Request.Headers;
            var memory = new MemoryStream();

            BlobServiceClient blobServiceClient = new BlobServiceClient("DefaultEndpointsProtocol=https;AccountName=blobstorage0516;AccountKey=eGier5YJBzr5z3xgOJUb+snTGDKhwPBJRFqb2nL5lcacmKZXHgY+LjmYapIHL7Csvgx75NwiOZE7kYLJfLqWBg==;EndpointSuffix=core.windows.net");
            BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("test");
            var blob =containerClient.GetBlobClient("test.mp4");
            StorageTransferOptions options = new StorageTransferOptions();
            options.InitialTransferLength = 1024 * 1024;
            options.MaximumConcurrency = 20;
            options.MaximumTransferLength = 4 * 1024 * 1024;
            await blob.DownloadToAsync(memory,null, options);
            memory.Position = 0;
            return File(memory, new MediaTypeHeaderValue("video/mp4").MediaType, true); //enableRangeProcessing = true



        }

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.