Maneira mais rápida de gravar imagens em Process.StandardInput.BaseStream
Estou tentando enviar um monte de imagens capturadas em desktop para um stdin de codificadores (FFmpeg).
O exemplo de código a seguir funciona.
aCaptureScreen()
função fornece uma imagem em 5-10 ms.
Se eu salvar a imagem em um MemoryStream, isso quase não leva tempo.
Mas eu só posso salvar uma imagem a cada 45 ms para 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());
}
A questão é:
Posso fazer o processo de salvamento mais rápido?
Eu tento ficar estável 60 fps dessa maneira