private void ProcessInfo()
{
string ffMPEG = System.IO.Path.Combine(Application.StartupPath, "ffMPEG.exe");
System.Diagnostics.Process mProcess = null;
System.IO.StreamReader SROutput = null;
string outPut = "";
string filepath = "D:\\source.mp4";
string param = string.Format("-i \"{0}\"", filepath);
System.Diagnostics.ProcessStartInfo oInfo = null;
System.Text.RegularExpressions.Regex re = null;
System.Text.RegularExpressions.Match m = null;
TimeSpan Duration = 0;
//Get ready with ProcessStartInfo
oInfo = new System.Diagnostics.ProcessStartInfo(ffMPEG, param);
oInfo.CreateNoWindow = true;
//ffMPEG uses StandardError for its output.
oInfo.RedirectStandardError = true;
oInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
oInfo.UseShellExecute = false;
// Lets start the process
mProcess = System.Diagnostics.Process.Start(oInfo);
// Divert output
SROutput = mProcess.StandardError;
// Read all
outPut = SROutput.ReadToEnd();
// Please donot forget to call WaitForExit() after calling SROutput.ReadToEnd
mProcess.WaitForExit();
mProcess.Close();
mProcess.Dispose();
SROutput.Close();
SROutput.Dispose();
//get duration
re = new System.Text.RegularExpressions.Regex("[D|d]uration:.((\\d|:|\\.)*)");
m = re.Match(outPut);
if (m.Success)
{
//Means the output has cantained the string "Duration"
string temp = m.Groups(1).Value;
string[] timepieces = temp.Split(new char[] { ':', '.' });
if (timepieces.Length == 4)
{
// Store duration
Duration = new TimeSpan(0, Convert.ToInt16(timepieces[0]), Convert.ToInt16(timepieces[1]), Convert.ToInt16(timepieces[2]), Convert.ToInt16(timepieces[3]));
}
}
}
Ошибки на линии:Я пытаюсь получить информацию о процессе и получить две ошибки, как я могу их решить?
TimeSpan Duration = 0;
Я не могу сбросить на 0 я также не присвоен нулевой к нему.
Ошибка 3 Не удается неявно преобразовать тип 'Int' в 'System.TimeSpan'
Вторая ошибка на линии:
string temp = m.Groups(1).Value;
Error 4 Non-член возможности ссылаться 'System.Text.RegularExpressions.Match.Groups' не может использоваться как метод .
Как насчет 'TimeSpan Duration = new TimeSpan (0)'? –
@MartinZabel ['TimeSpan.Zero' - это то же самое, что и' new TimeSpan (0) '] (http://referencesource.microsoft.com/#mscorlib/system/timespan.cs,66) :) –