【问题标题】:How can i compress video during upload on Azure BLOB storage using javascript in asp.net?如何在使用 asp.net 中的 javascript 在 Azure BLOB 存储上上传期间压缩视频?
【发布时间】:2017-10-06 00:37:44
【问题描述】:

我想在 azure BLOB 服务器上上传视频,我已经使用 javascript 成功上传了,但现在我想压缩视频大小或块大小上传期间。 有没有办法做到这一点。 提前致谢

【问题讨论】:

  • 不,它不同。我正在使用 azure.BLOB 存储,目前我正在通过 javascript 从 aspx 页面上传视频。但是视频太大了,所以我想压缩它。
  • 你想把它压缩到哪里?在上传整个文件之后在服务器上(在 ASP.NET 中),还是在上传文件之前在客户端网页中(在 javascript 中)?
  • 视频数据通常会被某些编解码器压缩 - 你不会得到太多压缩(即使你可以轻松做到)
  • 我想在网页客户端压缩它。

标签: javascript c# asp.net video azure-blob-storage


【解决方案1】:

很好,那么在服务器端怎么做呢?

我建议您可以使用ffmpeg 来压缩您的视频文件,并使用 azure web 作业。

您可以在 webjob 中使用以下命令来压缩您的视频文件。

-i {inputfile} -vcodec h264 -b:v 250k -acodec mp2  {outputfile}

您可以先将文件上传到您的 azure 网站根路径。然后您可以将文件名作为队列消息添加到 azure 队列存储中。

如果 webjob 找到文件名,它可以运行 ffmpeg 来压缩视频文件。完全压缩后,将该文件上传到blob存储并删除上传的文件。

更多细节,您可以参考以下步骤。

1.创建一些新文件夹来存放ffmpeg exe文件和上传/压缩文件。

2.创建一个 webjob 项目并从 Nuget 安装 mediatoolkit 包。

3.在webjobs函数中添加以下代码。

 public static void ProcessQueueMessage(
        [QueueTrigger("blobcopyqueue")] string filename, TextWriter log,
         [Blob("textblobs/{queueTrigger}", FileAccess.Write)] Stream blobOutput
        )
        {
            //set the input file path
            string inputfile = string.Format(@"D:\home\site\wwwroot\video\{0}", filename);
            //set the input file path
            string outputFile = string.Format(@"D:\home\site\wwwroot\video-compress\{0}", filename);

            using (var engine = new Engine(@"D:\home\site\wwwroot\compress\ffmpeg.exe"))
            {

                string command = string.Format(@"-i {0} -vcodec h264 -b:v 250k -acodec mp2  {1}", inputfile, outputFile);

                //you could change the command value as what you want to use
                engine.CustomCommand(command);
            }

            using (var fileStream = System.IO.File.OpenRead(outputFile))
            {
                fileStream.CopyTo(blobOutput);
            }

            //after compress delete the file.
            //File.Delete(inputfile);
            // File.Delete(outputFile);

        }

结果:

【讨论】:

    猜你喜欢
    • 2020-04-29
    • 2020-08-12
    • 2020-11-07
    • 1970-01-01
    • 2020-04-09
    • 2019-04-04
    • 2020-12-16
    • 2021-11-19
    • 2019-12-04
    相关资源
    最近更新 更多