如何在 C# 中使用 FFMPEG 以流作为输入

问题描述 投票:0回答:0

我想使用 FFmpeg 进行帧提取,并以流作为 C# 中的输入。但是,我在处理末尾存在元数据的文件时遇到失败。 FFmpeg 尝试读取元数据,这会导致它查找流的末尾。读取 Moov 原子后,无法在流中查找以提取帧。我正在积极寻求可能的解决方案来解决这个问题。另外,我想知道是否有任何现有的 FFmpeg C# 包装器可以有效地处理这个问题。

这就是我尝试在 C# 中使用 ffmpeg.exe 的方式

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();
ffmpeg video frame
© www.soinside.com 2019 - 2024. All rights reserved.