2

I have the following code that passes data to the ffmpeg process through a thread.

public void VideoToImages3()
{
    var inputFile = @"C:\testvideo.avi";
    var outputFile = @"C:\outputFile.mp4";

    var process = new Process
    {
        StartInfo = new ProcessStartInfo
        {
            RedirectStandardInput = true,
            UseShellExecute = false,
            CreateNoWindow = true,
            Arguments = $"-y -i - {outputFile}",
            FileName = _ffmpeg
        },
        EnableRaisingEvents = true
    };

    process.Start();

    //Write input data to input stream
    var inputTask = Task.Run(() =>
    {
        using (var input = new FileStream(inputFile, FileMode.Open))
        {
            input.CopyTo(process.StandardInput.BaseStream);
        }
    });

    Task.WaitAll(inputTask);

    process.WaitForExit();
}

In this case, I only upload 1 file through the stream (-i -). What if I need to stream multiple input files (-i - -i -). For example, when adding an Audio File to a Video File?

"ffmpeg -y -i {audioFilePath} -i {videoFilePath} {outputFilePath}"

How to transfer files via StandardInput if 2 input arguments are specified???

I can't find a solution

wohlstad
  • 12,661
  • 10
  • 26
  • 39
  • If you have file already, why not just pass it directly (-i pathtofile) instead of using input stream? – Evk Jan 18 '23 at 05:49
  • @Evk the problem is that there are cases when the file does not exist or it is in the form of bytes – Stiven Diplet Jan 18 '23 at 07:41
  • 1
    I guess the only way is to use named pipes as input (ffmpeg certainly accepts unix pipes, but I believe should accept windows too). You can't use stdin since there is only one for process. – Evk Jan 18 '23 at 11:32
  • Evk is correct, use named pipes. Here is an [example](https://stackoverflow.com/a/74622234/4926757) for using a named pipe with FFmpeg in C#. It's probably not the best example. There is a usage of `NamedPipeServerStream`... (I don't know enough C# to tell if this is the best way for using named pipes in C#). – Rotem Jan 18 '23 at 16:33

0 Answers0