【发布时间】:2011-02-10 13:17:48
【问题描述】:
我正在构建一个 cms,我希望用户能够上传视频,但我不熟悉视频上传和转换。是否有示例或有人编写过这样的解决方案? 我听说过 ffmpeg,但我不知道如何将它与 asp.net 集成。
作为简单的解决方案,我可以让我的客户上传 flv 文件,但我仍然需要从该 fvl 获取屏幕截图。
谢谢
【问题讨论】:
标签: asp.net flash flv video-processing video-encoding
我正在构建一个 cms,我希望用户能够上传视频,但我不熟悉视频上传和转换。是否有示例或有人编写过这样的解决方案? 我听说过 ffmpeg,但我不知道如何将它与 asp.net 集成。
作为简单的解决方案,我可以让我的客户上传 flv 文件,但我仍然需要从该 fvl 获取屏幕截图。
谢谢
【问题讨论】:
标签: asp.net flash flv video-processing video-encoding
回答作者的问题:
ffmpeg 是否需要安装 服务器端还是只用exe就够了?
ffmpeg.exe就足够了,不需要安装。
下面的代码在videoFilename变量指定的视频上获取captureTime的屏幕截图,并将其保存到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 参数给出。当然,请确保给定位置对于执行用户是可写的。
希望这对正在寻找正确语法的其他人也有用。
【讨论】: