62,041
社区成员
发帖
与我相关
我的任务
分享
private string RunProcess(string Parameters, bool UseShellExecute)
{
Process p = new Process();
p.StartInfo.FileName = this.FFmpegPath;
p.StartInfo.Arguments = Parameters;
p.StartInfo.CreateNoWindow = true;
if (!UseShellExecute)
{
p.StartInfo.UseShellExecute = UseShellExecute;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
}
string output = null; StreamReader srOutput = null;
try
{
p.Start();//启动线程
p.WaitForExit();
srOutput = p.StandardError;
output = srOutput.ReadToEnd();
System.Threading.Thread.Sleep(100);
}
catch (Exception)
{
output = string.Empty;
}
finally
{
if (srOutput != null)
{
srOutput.Close();
srOutput.Dispose();
}
p.Close();//关闭进程
p.Dispose();//释放资源
}
return output;
}
public void GetVideoInfo(VideoFile input)
{
string Params = string.Format("-i {0}", input.Path);
string output = RunProcess(Params, false);
input.RawInfo = output;
input.Duration = ExtractDuration(input.RawInfo);
input.BitRate = ExtractBitrate(input.RawInfo);
input.RawAudioFormat = ExtractRawAudioFormat(input.RawInfo);
input.AudioFormat = ExtractAudioFormat(input.RawAudioFormat);
input.RawVideoFormat = ExtractRawVideoFormat(input.RawInfo);
input.VideoFormat = ExtractVideoFormat(input.RawVideoFormat);
input.Width = ExtractVideoWidth(input.RawInfo);
input.Height = ExtractVideoHeight(input.RawInfo);
input.infoGathered = true;
}
private string RunProcess(string Parameters, bool UseShellExecute)
{
Process p = new Process();
p.StartInfo.FileName = this.FFmpegPath;
p.StartInfo.Arguments = Parameters;
p.StartInfo.CreateNoWindow = true;
if (!UseShellExecute)
{
p.StartInfo.UseShellExecute = UseShellExecute;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
}
string output = null; StreamReader srOutput = null;
try
{
string s = p.StandardOutput.ReadToEnd();
s = p.StandardError.ReadToEnd();
p.Start();//启动线程
p.WaitForExit();
s = p.StandardOutput.ReadToEnd();
srOutput = p.StandardError;
output = srOutput.ReadToEnd();
System.Threading.Thread.Sleep(100);
}
catch (Exception)
{
output = string.Empty;
}
finally
{
if (srOutput != null)
{
srOutput.Close();
srOutput.Dispose();
}
p.Close();//关闭进程
p.Dispose();//释放资源
}
return output;
}