我试图将许多桌面捕获的图像发送到编码器(FFmpeg)stdin。
以下代码示例有效。
CCD_ 1功能在5-10毫秒内提供图像。
如果我将图像保存在MemoryStream中,几乎不需要任何时间。
但我每45毫秒只能保存一个图像proc。标准输入。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帧/秒
这里的瓶颈是ffmpeg读取数据的速度与将数据压缩到.avi的速度相同,后者速度较慢。因此,您的img.Save
方法会阻塞,直到流的缓冲区中有一些空间写入数据为止。
你能做的不多。实时压缩60帧/秒的高清视频需要巨大的处理能力。