在 Azure 存储 Blob 上使用 .Net Core 和 C# 将图像序列转换为 MP4 文件

Convert image sequence to MP4 file using .Net Core and C# on Azure Storage Blobs

我有一个带有 POST 方法的 API,该方法捕获图像并将它们存储到 Azure 上的 blob 容器中。一旦准备好处理,这些图像将构成视频文件的一系列帧。我有另一个端点,当我的应用程序准备好处理序列并取回视频文件时,它会调用该端点。

我已准备就绪并准备好进行视频处理,但我仍然坚持如何实现我认为非常简单的目标!由于我的端点 运行s 在 .NET Core 中,我无法使用任何遗留的 .Net 库,并且由于我正在部署到可能需要扩展的 Azure WebApp (Windows OS) up/out 作为 DevOps 部署的一部分,我无法在硬件上安装预编译的 .Net Core 兼容 Nuget 包。

在这种情况下,我找不到 运行 任何好的库或示例。我 运行 在尝试使用与 GDI+ 或 FFMPEG 相关的任何内容时遇到问题...

希望找到类似于 SixLabors.ImageSharp

的内容

我有一个按顺序排列的所有图像列表,可以像这样进行处理:

var frames = new List<Image>();

// (Removed for brevity) Retrieve images from blobs & append to frame list...

foreach(var frame in frames)
{
    // Convert frames/sequence to video file
}

// Save to blob storage as .mp4

如有任何帮助,我们将不胜感激!

根据我的经验,将图像序列转换为视频流或文件的解决方案通常是使用一些流行的库,例如 ffmpeglibav

如果搜索C# ffmpeg images videoC# libav images video等关键字,您将获得很多有用的内容来帮助实现它,如下所示,您可以参考的线程很少。

  1. Image sequence to video stream?
  2. Converting Images into Video using C#
  3. tomaszzmuda/Xabe.FFmpeg

然后,您可以获取视频流或文件以块 blob 的形式上传到 Azure Blob 存储,请按照视频流的官方教程 Quickstart: Azure Blob storage client library for .NET to know how to use Azure Storage SDK for .NET standard and the key class in C# is CloudBlockBlob Class which functions enter link description hereBeginUploadFromFile for video file or BeginUploadFromStream

但是您的应用程序部署存在问题。由于Azure Web App sandbox about Win32k.sys (User32/GDI32) Restrictions如下图的限制,您不能将任何使用GDI系统调用的应用程序部署到Azure WebApp。

因此,为您的应用程序推荐的正常 Azure 服务是 Azure VM。


更新:

如果你考虑过使用dotNet Core来实现,我建议你可以尝试使用Azure App Service on Linux which be based on Docker and no limits for GDI. Also, Azure Batch是用任何语言实现你需求的另一种选择。我希望你能完成你的评估。