DEV Community

DeepakSharma
DeepakSharma

Posted on

FFMPEG with stream as an input in C#

I want to use FFmpeg for frame extraction with a stream as an input in C#. However, I am encountering a failure while processing files that have metadata present at the end. FFmpeg tries to read the metadata, which causes it to seek to the end of the stream. After reading the Moov atom, it is unable to seek back in the stream to extract the frames. I am actively seeking possible solutions to solve this problem. Additionally, I am wondering if there is any existing FFmpeg C# wrapper that handles this issue effectively.

This is how I was trying to use ffmpeg.exe in C#

using System.Diagnostics;
var inputArgs = "-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();

Top comments (0)