using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public static string ffmpegname;
public static string videoname; private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
public static string VideoConvertFlv(string FromName, string WidthAndHeight, string ExportName)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
//string Command = " -i " + FromName + "-tagpict "+":220:210"+" -ab 56 -ar 22050 -qmin 2 -qmax 16 -b 320k -r 15 -s" + WidthAndHeight + ExportName; //Flv格式
//p.StartInfo.Arguments = Command;
p.StartInfo.Arguments = "-i" + FromName + " -y -ab 56 -ar 22050 -b 500 -r 15 -s " + WidthAndHeight + ExportName;
p.StartInfo.FileName =ffmpegname;
//p.StartInfo.WorkingDirectory =; //HttpContext.Current.Server.MapPath("~/FLV/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
//p.ErrorDataReceived += new DataReceivedEventHandler(Output);//外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,
//开始执行
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
//p.StandardInput.WriteLine(Command);
//p.StandardInput.WriteLine("Exit ");
return ExportName;
} private void button1_Click(object sender, EventArgs e)
{
string strFile = videoname;
VideoConvertFlv(strFile, "320*240", "D:\\新建文件夹\\ffmpeg.rev12665\\zh.flv");
} private void 调用接口ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog opn = new OpenFileDialog();
opn.Filter = "文件|*.exe";
if (opn.ShowDialog() == DialogResult.OK)
{
ffmpegname = opn.FileName;
}
} private void 视频文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog opn = new OpenFileDialog();
opn.Filter = "MPEG文件|*.mpg|AVI文件|*.avi";
if (opn.ShowDialog() == DialogResult.OK)
{
videoname = opn.FileName;
}
}
}
}我建的windows窗体程序,上面就是我的全部程序内容我通过menustrip控件来获得ffmepg和视频文件的路径,然后通过button控件来执行转换视频的操作,我的程序没有报错,但是也没有执行,更没有生成转换的视频,有高手会吗?帮忙解答一下,万分感谢
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public static string ffmpegname;
public static string videoname; private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
public static string VideoConvertFlv(string FromName, string WidthAndHeight, string ExportName)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
//string Command = " -i " + FromName + "-tagpict "+":220:210"+" -ab 56 -ar 22050 -qmin 2 -qmax 16 -b 320k -r 15 -s" + WidthAndHeight + ExportName; //Flv格式
//p.StartInfo.Arguments = Command;
p.StartInfo.Arguments = "-i" + FromName + " -y -ab 56 -ar 22050 -b 500 -r 15 -s " + WidthAndHeight + ExportName;
p.StartInfo.FileName =ffmpegname;
//p.StartInfo.WorkingDirectory =; //HttpContext.Current.Server.MapPath("~/FLV/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
//p.ErrorDataReceived += new DataReceivedEventHandler(Output);//外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,
//开始执行
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
//p.StandardInput.WriteLine(Command);
//p.StandardInput.WriteLine("Exit ");
return ExportName;
} private void button1_Click(object sender, EventArgs e)
{
string strFile = videoname;
VideoConvertFlv(strFile, "320*240", "D:\\新建文件夹\\ffmpeg.rev12665\\zh.flv");
} private void 调用接口ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog opn = new OpenFileDialog();
opn.Filter = "文件|*.exe";
if (opn.ShowDialog() == DialogResult.OK)
{
ffmpegname = opn.FileName;
}
} private void 视频文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog opn = new OpenFileDialog();
opn.Filter = "MPEG文件|*.mpg|AVI文件|*.avi";
if (opn.ShowDialog() == DialogResult.OK)
{
videoname = opn.FileName;
}
}
}
}我建的windows窗体程序,上面就是我的全部程序内容我通过menustrip控件来获得ffmepg和视频文件的路径,然后通过button控件来执行转换视频的操作,我的程序没有报错,但是也没有执行,更没有生成转换的视频,有高手会吗?帮忙解答一下,万分感谢
上下中断。调试,然后在监视窗口取得Arguments的具体信息,把这些东西直接copy下来在cmd窗口运行,你看他报啥错!这是最直观的方法。另外的一些调试方法不适合新手玩,我就不介绍了。
解决方法就是先cmd,调试一下命令是否对的
//p.StartInfo.Arguments = "-i" + FromName + " -y -ab 56 -ar 22050 -b 500 -r 15 -s " + WidthAndHeight + ExportName;
//这句似乎有问题吧,-i后面没有空格,WidthAndHeight和ExportName之间也没有空格
//试试这样
p.StartInfo.Arguments = "-i " + FromName + " -y -ab 56 -ar 22050 -b 500 -r 15 -s " + WidthAndHeight + " " + ExportName;
//设置运行ffmpeg程序
System.Diagnostics.ProcessStartInfo FilestartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
//FilestartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
FilestartInfo.Arguments = " -i " + fileName + " -b 512 -r 24 -ab 32 -ar 22050 -vol 200 -s " + sizeOfFlv + " " + flv_file;
try
{
//转换
Process proc = Process.Start(FilestartInfo);
proc.WaitForExit();
我也刚做了这个东西 把关于输出流的东西都去掉就行了。正纳闷为什么不能拿输出呢