我做了一个wpf程序,需要从视频文件中截取一张图片作为缩略图,不需要打开视频播放,直接截取,我在网上找了一下:
string path = System.Windows.Forms.Application.StartupPath + "\tempImages\" + ofd.SafeFileName.Substring(0,ofd.SafeFileName.LastIndexOf('.')-1) + ".png";
FileStream stream = File.Open(path, FileMode.Create);
RenderTargetBitmap bmp = new RenderTargetBitmap(300,
300, 100, 100, PixelFormats.Pbgra32);
bmp.Render(me);
PngBitmapEncoder coder = new PngBitmapEncoder();
coder.Interlace = PngInterlaceOption.Off;
coder.Frames.Add(BitmapFrame.Create(bmp));
coder.Save(stream);
stream.Close();
但是做后的图片是一张空白的图,求大侠帮忙。
用ffmpeg截图。
using System.Diagnostics;
.....
ProcessStartInfo startInfo = new ProcessStartInfo("ffmpeg物理路径");
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = " -i 视频文件路径 -y -f image2 -ss 3 -t 0.001 -s 480*360 截图物理路径";//480*360是图片分辨率
startInfo.UseShellExecute = false;
try
{
Process.Start(startInfo);
return true;
}
catch
{
}