Write the data in cmd to memory instead of the file, catch it with C #

For a C # project, I'm experimenting with ffmpeg to extract a WAV file from a video file (on Windows). You can do this by running it on the command line as follows: "ffmpeg -i inputvid.avi +" additional options "+ extract.wav". This explicitly extracts the sound from the input .avi file to the specified .wav file.

Now I can easily run this command in C # to create the desired .wav file. However, I do not need this wav file so that it remains on the hard drive. For performance reasons, it would be much better if ffmpeg could temporarily store this file in memory, which can be used in my C # program. After running my WAV program, the file is no longer needed.

So, the actual question is: can I redirect the output file from the program to memory? And if possible, how can I read this in C #?

I know this is a long shot, and I very much doubt it, if possible, but I can always ask ...

Thanks in advance.

+3
source share
2 answers

Instead of specifying the output file name on the ffmpeg command line, use '-'. '-' tells ffmpeg to send stdout output . Please note that you may need to manually specify the output format on the command line, because ffmpeg can no longer output it from the file name (for this you may need the -f switch).

, stdout #.

+6

, !

, :

    System.Diagnostics.ProcessStartInfo psi =
    new System.Diagnostics.ProcessStartInfo(@"ffmpeg.exe");
    psi.Arguments = @"-i movie.avi -vn -acodec pcm_s16le -ar 44100 -ac 1 -f wav -";
    psi.RedirectStandardOutput = true;
    psi.UseShellExecute = false;
    Process proc = Process.Start(psi);
    System.IO.StreamReader myOutput = proc.StandardOutput;
    proc.WaitForExit();
    string output;
    if (proc.HasExited)
    {
        output = myOutput.ReadToEnd();
    }
    MessageBox.Show("Done!");

, cmd- . , , .

, , RedirectStandardOutput false, cmd.

: ffmpeg , #.

0

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


All Articles