2011-07-20 75 views

回答

3
public void GetVideoInfo(string input) 
    { 
     // set up the parameters for video info. 
     string @params = string.Format("-i {0}", input); 
     string output = Run(ffmpegProcess, @params); 

     //get the video format 
     re = new Regex("(\\d{2,3})x(\\d{2,3})"); 
     Match m = re.Match(output); 
     if (m.Success) 
     { 
      int width = 0; int height = 0; 
      int.TryParse(m.Groups[1].Value, out width); 
      int.TryParse(m.Groups[2].Value, out height); 
     } 
    } 

private static string Run(string process/*ffmpegFile*/, string parameters) 
    { 
     if (!File.Exists(process)) 
      throw new Exception(string.Format("Cannot find {0}.", process)); 

     // Create a process info. 
     ProcessStartInfo oInfo = new ProcessStartInfo(process, parameters); 
     //oInfo.UseShellExecute = false; 
     //oInfo.CreateNoWindow = true; 
     //oInfo.RedirectStandardOutput = true; 
     //oInfo.RedirectStandardError = true; 

     // Create the output and streamreader to get the output. 
     string output = null; 
     //StreamReader outputStream = null; 

     // Try the process. 
     //try 
     //{ 
     // Run the process. 
     Process proc = System.Diagnostics.Process.Start(oInfo); 

     proc.WaitForExit(); 

     //outputStream = proc.StandardError; 
     //output = outputStream.ReadToEnd();  

     proc.Close(); 
     //} 
     //catch(Exception ex) 
     //{ 
     // output = ex.Message; 
     //} 
     //finally 
     //{ 
     // // Close out the streamreader. 
     // if(outputStream != null) 
     //  outputStream.Close(); 
     //} 
     return output; 
    } 

您應取消註釋某些代碼以使其正常工作。希望能幫助到你。

我有從視頻,不同轉換等獲取更多信息的代碼。上面的代碼被切片,可能需要稍作修改。

+0

感謝mynkow。讓我試試看。 – GethuJohn