刘立强 2017-07-04 11:53 采纳率: 0%
浏览 3831

C# 如何从视频文件中截取图片?

我做了一个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();

但是做后的图片是一张空白的图,求大侠帮忙。

  • 写回答

1条回答

  • Go 旅城通票 2017-07-04 12:51
    关注

    用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
                {
                }
    
    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗