2011-01-20 141 views
3

嗨,有人可以告訴我如何執行以下命令對C#中的FFmpeg。使用C執行ffmpeg命令#

mkfifo temp1.a 
mkfifo temp1.v 
mkfifo temp2.a 
mkfifo temp2.v 
mkfifo all.a 
mkfifo all.v 
ffmpeg -i input1.flv -vn -f u16le -acodec pcm_s16le -ac 2 -ar 44100 - > temp1.a < /dev/null & 
ffmpeg -i input2.flv -vn -f u16le -acodec pcm_s16le -ac 2 -ar 44100 - > temp2.a < /dev/null & 
ffmpeg -i input1.flv -an -f yuv4mpegpipe - > temp1.v < /dev/null & 
{ ffmpeg -i input2.flv -an -f yuv4mpegpipe - < /dev/null | tail -n +2 > temp2.v ; } & 
cat temp1.a temp2.a > all.a & 
cat temp1.v temp2.v > all.v & 
ffmpeg -f u16le -acodec pcm_s16le -ac 2 -ar 44100 -i all.a \ 
     -f yuv4mpegpipe -i all.v \ 
     -sameq -y output.flv 
rm temp[12].[av] all.[av] 

在此先感謝您。

回答

1

您可以使用Process.Start方法從System.Diagnostics命名空間。

+0

格雷格您好,感謝回去我。我知道如何執行exe文件。我遇到的問題是我不知道如何執行這些命令,你是否將它作爲exe文件的一個參數執行,或者將參數拆分並多次調用exe。這就是我所堅持的。 – Paul 2011-01-20 17:31:33

0

您可以從官方網站下載ffmpeg的可執行文件,並將它們放在您的應用程序啓動路徑中,然後使用Process.Start()執行它們,然後根據您的需要傳遞參數。

例子: -

exe文件路徑 - ffprobe.exe -hide_banner -show_format -show_streams -pretty {} video_file

private static string Execute(string exePath, string parameters) 
{ 
string result = String.Empty; 

using (Process p = new Process()) 
{ 
    p.StartInfo.UseShellExecute = false; 
    p.StartInfo.CreateNoWindow = true; 
    p.StartInfo.RedirectStandardOutput = true; 
    p.StartInfo.FileName = exePath; 
    p.StartInfo.Arguments = parameters; 
    p.Start(); 
    p.WaitForExit(); 

    result = p.StandardOutput.ReadToEnd(); 
} 

return result; 
}