Run ffmpeg command using C #

Hi, someone will show me how to execute the following command from 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]

Thanks in advance.

+3
source share
2 answers

You can use the method Process.Startfrom the namespace System.Diagnostics.

+1
source

You can download executable files ffmpegfrom the official website and put them in the application launch path, and then execute them with Process.Start()and then pass arguments 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;
}
0
source

Source: https://habr.com/ru/post/1786721/


All Articles