我正在构建一个 cms,我希望用户能够上传视频,但我不熟悉视频上传和转换。是否有示例或有人编写过这样的解决方案?我听说过 ffmpeg,但我不知道如何将它与 asp.net 集成。
作为简单的解决方案,我可以让我的客户上传 flv 文件,但我仍然需要从该 fvl 获取屏幕截图。
谢谢
我正在构建一个 cms,我希望用户能够上传视频,但我不熟悉视频上传和转换。是否有示例或有人编写过这样的解决方案?我听说过 ffmpeg,但我不知道如何将它与 asp.net 集成。
作为简单的解决方案,我可以让我的客户上传 flv 文件,但我仍然需要从该 fvl 获取屏幕截图。
谢谢
回答作者的问题:
ffmpeg 需要安装在服务器端还是只需要安装 exe 就足够了?
ffmpeg.exe 就足够了,不需要安装。
下面的代码获取captureTime
由变量指定的视频的屏幕截图videoFilename
,并将其保存到imageFilename
路径中。
Process ffmpeg = new Process();
ffmpeg.EnableRaisingEvents = true;
ffmpeg.StartInfo = new ProcessStartInfo
{
FileName = this.ffmpegPath,
Arguments = string.Format(
"-i \"{0}\" -an -y -s 320x240 -ss {1} -vframes 1 -f image2 \"{2}\"",
this.videoFilename,
DateTime.MinValue.Add(this.captureTime).ToString("HH:mm:ss:ff", CultureInfo.InvariantCulture),
this.imageFilename
),
WorkingDirectory = this.workingDirectory,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
WindowStyle = ProcessWindowStyle.Hidden
};
ffmpeg.Start();
ffmpeg.WaitForExit(this.timeout);
我使用过 ffmpeg,但我发现使用预编译的 .exe 版本更容易。所以在后端,我只需使用所需的命令行参数启动 ffmpeg.exe 来进行转换,让它运行,当它完成时,完成的文件就准备好了。
很久很久以前,在我的 PHP4 日子里,我使用了以下方法,在 shell 上调用 ffmpeg 并创建屏幕截图。
/**
* Create a snapshot of a videofile and save it in jpeg format
*/
function snapshot($sourcefile,$destfile,$width=184,$height=138,$time=1){
$width=floor(($width)/2)*2;
$height=floor(($height)/2)*2;
exec("ffmpeg -i {$sourcefile} -s {$width}x{$height} -t 0.0001 -ss {$time} -f mjpeg {$destfile}");
}
它将支持的视频文件作为 $sourcefile。屏幕截图所需的文件位置可以由 $destfile 参数给出。当然,请确保给定位置对于执行用户是可写的。
希望这对正在寻找正确语法的其他人也有用。