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

How do properly stream a video using partial content ranges from Azure blob storage?

我有一个 mp4 视频已上传到 Azure Blob 存储(块,存储 v2)。我无法使用 <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 媒体服务的建议,但这似乎有点过分了,这应该是仅受支持而无需合并其他服务的东西。

任何 help/suggestions 将不胜感激 - 谢谢!

根据我的研究,如果将enableRangeProcessing参数设置为true,我们会得到范围响应。更多细节请参考.

我的测试代码

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



        }