1

I have a System.io stream object which is raw pcm data, if i want to convert it using ffmpeg what command shall I use

1 Answers1

1

You need to pipe your stream to ffmpeg process. This blog is helpful https://mathewsachin.github.io/blog/2017/07/28/ffmpeg-pipe-csharp.html

Here if that link goes down

using System.Diagnostics;

var inputArgs = "-framerate 20 -f rawvideo -pix_fmt rgb32 -video_size 1920x1080 -i -";
var outputArgs = "-vcodec libx264 -crf 23 -pix_fmt yuv420p -preset ultrafast -r 20 out.mp4";

var process = new Process
{
    StartInfo =
    {
        FileName = "ffmpeg.exe",
        Arguments = $"{inputArgs} {outputArgs}",
        UseShellExecute = false,
        CreateNoWindow = true,
        RedirectStandardInput = true
    }
};

process.Start();

var ffmpegIn = process.StandardInput.BaseStream;

// Write Data
ffmpegIn.Write(Data, Offset, Count);

// After you are done
ffmpegIn.Flush();
ffmpegIn.Close();

// Make sure ffmpeg has finished the work
process.WaitForExit();
Wanton
  • 800
  • 6
  • 9
  • 1
    how exactly shall i input audio stream object the write method does not work for me –  Dec 09 '18 at 12:01
  • Use `Stream.CopyTo` https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.copyto?view=netframework-4.7.2 – Wanton Dec 09 '18 at 12:03