2017-09-10 32 views
0

我使用的是FFMPEG Process收集有关文件的一些信息:C#工艺参数和输出缺

private void GatherFrames() 
{ 
    Process process = new Process(); 
    process.StartInfo.FileName = "ffmpeg"; 
    process.StartInfo.Arguments = "-i \"" + filePath + "\""; 
    process.StartInfo.RedirectStandardError = true; 
    process.StartInfo.UseShellExecute = false; 

    if (!process.Start()) 
    { 
     Console.WriteLine("Error starting"); 
     return; 
    } 
    StreamReader reader = process.StandardError; 
    string line; 
    while ((line = reader.ReadLine()) != null) 
    { 
     outputRichTextBox.AppendText(line + "\n"); 
    } 
    process.Close(); 
} 

这似乎正常工作。现在,我想只是FrameRatethanks to other posts,我发现ffprobe可用来做到这一点:

public void GetFrameRate() 
{ 
    Process process = new Process(); 
    process.StartInfo.FileName = "ffprobe"; 
    process.StartInfo.Arguments = "-v 0 -of compact=p=0 -select_streams 0 -show_entries stream = r_frame_rate \"" + filePath + "\""; 
    Console.WriteLine(process.StartInfo.Arguments); 
    process.StartInfo.RedirectStandardError = true; 
    process.StartInfo.RedirectStandardOutput = true; 
    process.StartInfo.UseShellExecute = false; 
    process.StartInfo.CreateNoWindow = false; 
    Console.WriteLine(process.StartInfo); 

    if (!process.Start()) 
    { 
     Console.WriteLine("Error starting"); 
     return; 
    } 

    StreamReader reader = process.StandardError; 
    string line; 
    while ((line = reader.ReadLine()) != null) 
    { 
     Console.WriteLine(line); 
    } 
    process.Close(); 
} 

这似乎并没有在所有的工作。该过程开始,但不会返回我期望返回的内容。

如果我手动运行该命令,我做cmd.exe如下:

> e: 
> cd "FILE_PATH" 
> ffprobe -v 0 -of compact=p=0 -select_streams 0 -show_entries stream=r_frame_rate "FILE_NAME.mp4" 
r_frame_rate=60/1 

注:-show_entries stream = r_frame_rate不起作用,只有-show_entries stream=r_frame_rate无空格。


我不知道如何正确地使用Process来做这件事。

回答

0

我试过你的论点,并通过StandardOutput属性得到了输出。 请将您的代码更改为下方并再次尝试。

StreamReader reader = process.StandardOutput;