1 /// <summary>
2 /// 截图
3 /// </summary>
4 /// <param name="sender"></param>
5 /// <param name="e"></param>
6 private void btnCut_Click(object sender, EventArgs e)
7 {
8 //判断是否在播放
9 if (!isPlay)
10 {
11 MessageBox.Show("请先加载视频再截取");
12 return;
13 }
14 this.label1.Text = "截图中.....请稍后";
15
16 //获取播放进度位置
17 string position=this.axWindowsMediaPlayer1.Ctlcontrols.currentPosition.ToString();
18 //开始位置
19 string begin=position.Split('.')[0];
20 //结束位置
21 string end=position.Split('.')[1];
22 //图片存放位置
23 string image=Application.StartupPath+"\\"+begin+end+".jpg";
24
25 //定义一个进程
26 Process process = new Process();
27 //调用ffmpeg截图工具
28 process.StartInfo.FileName = "ffmpeg.exe";
29 //隐藏截图工具窗口
30 process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
31 //设置工具命令参数
32 process.StartInfo.Arguments = " -i " + this.videoPath + " -ss " + begin + " -t " + end + " -s 412x366 " + image;
33
34 try
35 {
36 //启动进程
37 process.Start();
38 process.WaitForExit();
39 //显示图片
40 this.pictureBox1.Load(image);
41 //显示图片保存路径
42 this.label1.Text = "截图保存路径:"+image;
43 }
44 catch
45 {
46 MessageBox.Show("请将视频文件放在C盘根目录下");
47 }
48 finally
49 {
50 //结束进程
51 process.Close();
52 }
53 }