62,046
社区成员
发帖
与我相关
我的任务
分享
class VideoProcess
{
public delegate void ProgressBar(int count, int time, int timeCount);
public event ProgressBar progressBar;
string propertytime = "";
private string _Command;
private string _FileName;
public string Command
{
get { return _Command; }
set{_Command = value;}
}
public string FileName
{
get { return _FileName; }
set { _FileName = value; }
}
public VideoProcess(string setCommand,ConvertType.Menu type)
{
this.Command = setCommand;
switch (type) {
case ConvertType.Menu.ffmepg:
this.FileName = System.IO.Path.GetFullPath("system/ffmpeg.exe");
break;
case ConvertType.Menu.ffmepgcut:
this.FileName = System.IO.Path.GetFullPath("system/ffmpeg_cut.exe");
break;
case ConvertType.Menu.mp4box:
this.FileName = System.IO.Path.GetFullPath("system/MP4Box.exe");
break;
case ConvertType.Menu.mencoder:
this.FileName = System.IO.Path.GetFullPath("system/mencoder.exe");
break;
}
}
public void Progress()
{
try
{
Process p = new Process();
p.StartInfo.FileName = this.FileName;
p.StartInfo.Arguments = this.Command;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
}
catch
{
}
}
void p_ErrorDataReceived(object sendProcess, DataReceivedEventArgs output)
{
if (!String.IsNullOrEmpty(output.Data))
{
Regex _itemexs = new Regex(@"Duration: (?<Time>(\d+):(\d+):(\d+).(\d+)),");
MatchCollection _matches = _itemexs.Matches(output.Data);
foreach (Match item in _matches)
{
propertytime = item.Groups["Time"].Value;
}
Regex _itemex = new Regex(@"frame=(\s*)(\d+) fps= (\d+) q=((\.|\d)+) size=(\s*)(?<size>(\d+))kB time=(\s*)(?<times>(\d|\.)+) bitrate=(\s*)((\d|\.)+)kbits/s");
MatchCollection _itemmatches = _itemex.Matches(output.Data);
foreach (Match itemmatch in _itemmatches)
{
string propertyname = itemmatch.Groups["size"].Value;
string propertytimes = itemmatch.Groups["times"].Value;
int timecount = DateTime.Parse(propertytime).Hour * 3600 + DateTime.Parse(propertytime).Minute * 60 + DateTime.Parse(propertytime).Second;
int times = int.Parse(Math.Ceiling(double.Parse(propertytimes)).ToString());
progressBar(int.Parse(propertyname), times, timecount);
}
}
}
}