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

aar*_*ark 1 c# video-streaming html5-video azure-blob-storage asp.net-core-3.1

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

(更糟糕的是,虽然与我的问题不完全相关,因为我认为这更多是浏览器问题,但视频设置为循环,并且每次循环都会重新下载。)

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

我尝试直接获取视频,为<video>标签src属性提供绝对 URI;我还尝试通过 ASP .NET Core 3.1 控制器方法提供视频,返回 aFileStreamResult并将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);
}
Run Code Online (Sandbox Code Playgroud)

似乎无论我尝试什么,我都无法获得带有 206 状态代码的范围响应。我已经看到了有关使用 Azure 媒体服务的建议,但这似乎有点矫枉过正,这应该是只需支持而无需合并其他服务的东西。

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

Jim*_* Xu 6

根据我的研究,如果将enableRangeProcessing参数设置为true,我们将得到范围response\xe3\x80\x82 更多详细信息,请参阅问题

\n\n

我的测试代码

\n\n
public async Task<IActionResult> Video() {\n            var s = Request.Headers;\n            var memory = new MemoryStream();\n\n            BlobServiceClient blobServiceClient = new BlobServiceClient("DefaultEndpointsProtocol=https;AccountName=blobstorage0516;AccountKey=eGier5YJBzr5z3xgOJUb+snTGDKhwPBJRFqb2nL5lcacmKZXHgY+LjmYapIHL7Csvgx75NwiOZE7kYLJfLqWBg==;EndpointSuffix=core.windows.net");\n            BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("test");\n            var blob =containerClient.GetBlobClient("test.mp4");\n            StorageTransferOptions options = new StorageTransferOptions();\n            options.InitialTransferLength = 1024 * 1024;\n            options.MaximumConcurrency = 20;\n            options.MaximumTransferLength = 4 * 1024 * 1024;\n            await blob.DownloadToAsync(memory,null, options);\n            memory.Position = 0;\n            return File(memory, new MediaTypeHeaderValue("video/mp4").MediaType, true); //enableRangeProcessing = true\n\n\n\n        }\n
Run Code Online (Sandbox Code Playgroud)\n\n

在此输入图像描述

\n