我想在azure BLOB服务器上上传视频,我已经使用javascript成功上传了,但现在我想压缩视频大小或 block 大小上传期间。 有什么办法可以做到这一点吗? 提前致谢。
最佳答案
of fine ,then how to do it on server side?
我建议你可以使用ffmpeg使用 azure web 作业压缩视频文件。
您可以在网络作业中使用以下命令来压缩您的视频文件。
-i {inputfile} -vcodec h264 -b:v 250k -acodec mp2 {outputfile}
您可以首先将文件上传到您的 azure 网站根路径。然后您可以将文件名作为队列消息添加到 azure 队列存储中。
如果网络作业找到文件名,它就可以运行 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);
}
关于javascript - 如何在 asp.net 中使用 javascript 在 Azure BLOB 存储上上传期间压缩视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43840364/