We need to read some RTSP streams in C# using ffmpeg and pipe the stdout to a MemoryStream
. We need to get a snapshot out of each stream. Here's my code so far:
var arguments =
$@" -y -i {imageUri.AbsoluteUri} -vframes 1 -pix_fmt yuvj420p -vf select='eq(pict_type\,I)' -q:v 1 pipe:1";
var processStartInfo = new ProcessStartInfo
{
Arguments = arguments,
FileName = AppDomain.CurrentDomain.BaseDirectory + @"\lib\ffmpeg.exe",
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var process = new Process
{
StartInfo = processStartInfo,
EnableRaisingEvents = true
};
process.Start();
var output = process.StandardError.Read();
process.StandardOutput.BaseStream.CopyTo(memoryStream);
But with above memoryStream.Length
is always 0
. What's going on? I've looked at this: How to get output from ffmpeg process in c# but I'm reading binary from stdout. And this answer gives little implementation details: https://stackoverflow.com/a/4535927/177416
Wasn't sure how to use this answer: .NET Process - Redirect stdin and stdout without causing deadlock