void button1_Click(object sender, EventArgs e)
{
textBox1.AppendText(Ping ());
}
string Ping()
{
using (Process p = new Process())
{
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中 string sourceFile = tbPath.Text.ToString();
string size = comboBox1.SelectedItem.ToString();//"
string TargetFile = sourceFile.Substring(0, sourceFile.Length - 5) + ".flv"; p.Start();
//-ss参数作用:可以从指定时间点开始转换任务其后跟时间的单位,-s指定分辨率(368*208,输出的分辨率为368*208,注意的是片源一定要是16:9的不然会变形)
//-r帧数只能设定为(15-29.97)
//-b<比特率>指定平均压缩比特率,例:(768,1500……),-ac<数值>设定声道熟,1是单声道,2是立体声
//-i"1.avi"(输入文件是和ffmpeg在同一目录下的1.avi文件,可以自己加路径改名字),-ar24000(声音的采样频率)
//-ab128(音频数据流量,一般选择32,64,96,128),-vol 200(200%'的音量,自己设置),-y覆盖输出文件,即如果文件已经存在的话,不经提示就覆盖
p.StandardInput.WriteLine("ffmpeg.exe -i " + sourceFile + " -ab 32 -ar 22050 -b 800000 -s 320*240 " + TargetFile + "> D:\\aaagf.txt");
p.StandardInput.WriteLine("exit");
p.StandardOutput.ReadToEnd(); p.WaitForExit(6000);
string path = @"D:\aaagf.txt";
return File.ReadAllText(path); p.Close(); }
}
谁能将此问题解决,给60分!前天申请csdn发3个帖子没一个回复是有用的!
{
textBox1.AppendText(Ping ());
}
string Ping()
{
using (Process p = new Process())
{
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中 string sourceFile = tbPath.Text.ToString();
string size = comboBox1.SelectedItem.ToString();//"
string TargetFile = sourceFile.Substring(0, sourceFile.Length - 5) + ".flv"; p.Start();
//-ss参数作用:可以从指定时间点开始转换任务其后跟时间的单位,-s指定分辨率(368*208,输出的分辨率为368*208,注意的是片源一定要是16:9的不然会变形)
//-r帧数只能设定为(15-29.97)
//-b<比特率>指定平均压缩比特率,例:(768,1500……),-ac<数值>设定声道熟,1是单声道,2是立体声
//-i"1.avi"(输入文件是和ffmpeg在同一目录下的1.avi文件,可以自己加路径改名字),-ar24000(声音的采样频率)
//-ab128(音频数据流量,一般选择32,64,96,128),-vol 200(200%'的音量,自己设置),-y覆盖输出文件,即如果文件已经存在的话,不经提示就覆盖
p.StandardInput.WriteLine("ffmpeg.exe -i " + sourceFile + " -ab 32 -ar 22050 -b 800000 -s 320*240 " + TargetFile + "> D:\\aaagf.txt");
p.StandardInput.WriteLine("exit");
p.StandardOutput.ReadToEnd(); p.WaitForExit(6000);
string path = @"D:\aaagf.txt";
return File.ReadAllText(path); p.Close(); }
}
谁能将此问题解决,给60分!前天申请csdn发3个帖子没一个回复是有用的!
_process.OutputDataReceived += new DataReceivedEventHandler(
ProcessOutputDataReceived);
这样就行了。
{
string avPath = MapPath(or_path);
s_progress = null;
s_progress = RadProgressContext.Current;
Process p = new Process();//建立外部调用线程
p.StartInfo.FileName = common.FFmpeg_path;
p.StartInfo.Arguments = String.Format(common.FFmpeg_arg, avPath, MapPath(savePath)); ;//参数
p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)
p.StartInfo.RedirectStandardError = true;
p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
p.StartInfo.CreateNoWindow = true;//不创建进程
p.Start();//启动线程
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
} int i = 0;
void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
if (!String.IsNullOrEmpty(e.Data))
{
i++;
if (i == 10)
{
string tempstr = e.Data.Replace("Duration:", "").Trim();
tempstr = tempstr.Substring(0, tempstr.IndexOf(',') - 1);
var ab = Convert.ToDateTime(tempstr);
s_progress["SecondaryTotal"] = (ab.TimeOfDay.TotalSeconds + 5).ToString();
}
if (i >= 15)
{
try
{
string t = e.Data.Substring(e.Data.IndexOf("time=") + 5).Split(' ')[0];
s_progress["SecondaryPercent"] = (Convert.ToDecimal(t) * 100 / Convert.ToDecimal(s_progress["SecondaryTotal"])).ToString("##.##");
}
catch (Exception ex)
{
}
}
s_progress["CurrentOperationText"] = e.Data;
}
else
{ s_progress["SecondaryPercent"] = "100";
}
}
}当时是web项目,使用了radupload,所以代码里面会有一些radupload控件的控制参赛,这个你可以不用管,主体部分就是截获cmd的输出,然后根据ffmpeg输出格式分析进度(当然我这里是要做进度显示,如果你只是需要把输出直接显示到TextBox里也没必要这么复杂,直接他e.Data输出就成了)
望大哥指点一二……