5

多くのデスクトップでキャプチャされた画像をエンコーダー (FFmpeg) stdin に送信しようとしています。

次のコード例は機能します。

このCaptureScreen()関数は、5 ~ 10 ミリ秒で画像を提供します。

画像を MemoryStream に保存すると、ほとんど時間がかかりません。

しかし、45 ミリ秒ごとに 1 つの画像しか proc.StandardInput.BaseStream に保存できません。

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());
}

質問は:

保存プロセスをより速く行うことはできますか?

この方法で安定した60 fpsを取得しようとします

4

1 に答える 1

2

ここでのボトルネックは、ffmpeg が .avi に圧縮するのと同じ速度でデータを読み取ることです。これは遅いです。したがってimg.Save、ストリームのバッファにデータを書き込むためのスペースができるまで、メソッドはブロックされます。

あなたができることはあまりありません。60 fps の HD ビデオをリアルタイムで圧縮するには、膨大な処理能力が必要です。

于 2012-09-04T07:22:03.130 に答える