Execute ffmpeg command with C#

陌路散爱 提交于 2021-01-03 06:48:12

问题


Hi can someone show me how you would execute the following command against FFmpeg in C#.

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]

Thank you in advance.


回答1:


You can use Process.Start method from System.Diagnostics namespace.




回答2:


You can download the executable files of ffmpeg from the official site and place them in your application startup path and then eecute them using the Process.Start() and after then pass on the arguments to that according to your needs.

Example:-

exe path- 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;
}


来源:https://stackoverflow.com/questions/4749967/execute-ffmpeg-command-with-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!