using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using static System.Net.Mime.MediaTypeNames;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace 视频转bmp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string path;
List<Point> list = new List<Point>();
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "MP4文件(*.MP4)|*.MP4";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
path = openFileDialog1.FileName;
}
string str = System.Environment.CurrentDirectory;
var str_MyProg = str + "\\ffmpeg\\bin\\ffmpeg.exe";
string name = System.IO.Path.GetFileNameWithoutExtension(path);
if (Directory.Exists("File\\" + name + "\\image"))
{
Directory.Delete("File\\" + name + "\\image", true);
command(str, name, str_MyProg);
}
else
{
command(str, name, str_MyProg);
}
}
void command(string str, string name, string str_MyProg)
{
Directory.CreateDirectory("File\\" + name + "\\image"); //创建此文件夹
Directory.CreateDirectory("File\\" + name + "\\PSAF"); //创建此文件夹
string save_folder = str + "\\File\\" + name + "\\image\\";
//#设置参数以直接输出图像序列(帧)
string str_CommandArgs = "-i " + path + " -vf fps=25/2 " + save_folder + "n_%03d.bmp"; //the n_%03d replaces "n++" count
Process process = new Process();
System.Diagnostics.ProcessStartInfo cmd_StartInfo = new System.Diagnostics.ProcessStartInfo(str_MyProg, str_CommandArgs);
cmd_StartInfo.WindowStyle = ProcessWindowStyle.Normal;
cmd_StartInfo.RedirectStandardError = false; //set false
cmd_StartInfo.RedirectStandardOutput = false; //set false
cmd_StartInfo.UseShellExecute = true; //set true
cmd_StartInfo.CreateNoWindow = true; //don't need the black window
//创建一个进程,分配它的ProcessStartInfo并启动它
System.Diagnostics.Process cmd = new System.Diagnostics.Process();
cmd.StartInfo = cmd_StartInfo;
cmd.Start();
}
}
}