c#.net 如何使用ffmpeg截图

在.net项目中经常遇到上传完视频需要自动对某一帧进行截图,这里贴出使用ffmpeg进行自动截图的方法

首先下载ffmpeg.exe文件

https://pan.baidu.com/s/1GS9ISoZvKfs9GA7_szvvlw

具体写法如下

String from = "C:\\WWW\\1530423892.mp4";
String to = "C:\\WWW\\1530423892.png";

string ffmpegPath = Server.MapPath("~/ffmpeg/ffmpeg.exe");//指定上传文件在服务器上的保存路径
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(ffmpegPath);
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.Arguments = "-ss 00:01:16 -i  " + from + " -f image2 -y " + to;
System.Diagnostics.Process.Start(startInfo);

其中笔者是把fmpeg直接放在网站根目录下的,所以文件路径采用相对路径

from和to两个路径 分别代表视频的绝对路径和截图后图片的保存路径 01:16表示截图的时间,可根据自己需要进行调整

c#.net 如何使用ffmpeg截图