我使用的是最新和推荐的 Azure.Storage.Blobs
包。我把视频文件以块状上传,效果不错。现在的问题是将视频回传到web客户端,这就是 videojs
. 玩家正在使用 Range
请求。
我的端点。
[HttpGet]
[Route("video/{id}")]
[AllowAnonymous]
public async Task<IActionResult> GetVideoStreamAsync(string id)
{
var stream = await GetVideoFile(id);
return File(stream, "video/mp4", true); // true is for enableRangeProcessing
}
而我的 GetVideoFile
办法
var ms = new MemoryStream();
await blobClient.DownloadToAsync(ms, null, new StorageTransferOptions
{
InitialTransferLength = 1024 * 1024,
MaximumConcurrency = 20,
MaximumTransferLength = 4 * 1024 * 1024
});
ms.Position = 0;
return ms;
视频被下载和流媒体就好了。但它下载整个视频和不尊重。Range
完全没有。我也试过用 DownloadTo(HttpRange)
var ms = new MemoryStream();
// parse range header...
var range = new HttpRange(from, to);
BlobDownloadInfo info = await blobClient.DownloadAsync(range);
await info.Content.CopyToAsync(ms);
return ms;
但是在浏览器中什么都没有显示。有什么办法可以实现?
请尝试将内存流的位置重新设置为--------------------------。0
才返回。
var ms = new MemoryStream();
// parse range header...
var range = new HttpRange(from, to);
BlobDownloadInfo info = await blobClient.DownloadAsync(range);
await info.Content.CopyToAsync(ms);
ms.Position = 0;//ms is positioned at the end of the stream so we need to reset that.
return ms;
我相信只有使用Azure Blob是不可能实现的。更多信息在这里。https:/stackoverflow.coma260539101384539
但总的来说,你可以使用一个提供Seek Start End位置的CDN。https:/docs.vdms.comcdnre3ContentStreamingHPDSeeking_Within_a_Video.htm。
另一种可能是使用支持流媒体的Azure媒体服务。你的做法其实是一种渐进式下载,这和我们的想法不完全一样,你可能会花很多的网络出。(假设你有很多人访问同一个文件)