很好,那么在服务器端怎么做呢?
我建议您可以使用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);
}
结果: