多くのデスクトップキャプチャ画像をエンコーダ(FFmpeg)標準に送信しようとしています。Process.StandardInput.BaseStreamに画像を書き込むための高速な方法
次のコード例は機能します。
CaptureScreen()
機能は、5〜10 msの画像を提供します。
イメージをMemoryStreamに保存すると、ほとんど時間がかかりません。
しかし、私は proc.StandardInput.BaseStreamに45 msごとに1つの画像しか保存できません。
public void Start(string bitrate, string buffer, string fps, string rtmp, string resolution, string preset)
{
proc.StartInfo.FileName = myPath + "\\ffmpeg.exe";
proc.StartInfo.Arguments = "-f image2pipe -i pipe:.bmp -vcodec libx264 -preset " + preset + " -maxrate " + bitrate + "k -bufsize " +
buffer + "k -bt 10 -r " + fps + " -an -y test.avi"; //+ rtmp;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
Stopwatch st = new Stopwatch();
BinaryWriter writer = new BinaryWriter(proc.StandardInput.BaseStream);
System.Drawing.Image img;
st.Reset();
st.Start();
for (int z = 0; z < 100; z++)
{
img = ScrCap.CaptureScreen();
img.Save(writer.BaseStream, System.Drawing.Imaging.ImageFormat.Bmp);
img.Dispose();
}
st.Stop();
System.Windows.Forms.MessageBox.Show(st.ElapsedMilliseconds.ToString());
}
質問です:
は私が速く保存処理を行うことができますか?
私はここでボトルネックがffmpegのは、それが遅くなる、.AVIするためにそれを圧縮し、同じ速度でデータを読み込むことである
'ImageFormat.png'で試したことがありますので、実際に読み書きするデータ量は少なくなっていますか? – PhonicUK
私はそれを試しました。そのより遅い... 130 ms – Hasibii