更快的写入图像Process.StandardInput.BaseStream方式 [英] Faster way to write image to Process.StandardInput.BaseStream

查看:361
本文介绍了更快的写入图像Process.StandardInput.BaseStream方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着发送大量桌面捕捉图像的编码器(FFmpeg的)标准输入。



下面的代码示例工作。



CaptureScreen()函数在5-10毫秒提供的图像。



如果我将图像保存在一个MemoryStream它几乎不需要花时间。




但我只能节省1每隔45毫秒至
proc.StandardInput.BaseStream形象。




 公共无效启动(字符串比特率,字符串缓冲区,字符串FPS,串RTMP,串分辨率,串预置)
{
proc.StartInfo.FileName = mypath中+\\ffmpeg。可执行程序;
proc.StartInfo.Arguments =-f image2pipe -i管:.BMP -vcodec libx264 -PRESET+预置+-maxrate+比特率+K -bufsize+
缓冲区+K -bt 10 -r+ FPS +-an -y test.avi // + RTMP;
proc.StartInfo.UseShellExecute = FALSE;
proc.StartInfo.RedirectStandardInput = TRUE;
proc.StartInfo.RedirectStandardOutput = TRUE;

proc.Start();

秒表ST =新的秒表();
的BinaryWriter作家=新的BinaryWriter(proc.StandardInput.BaseStream);
为System.Drawing.Image IMG;

st.Reset();
st.Start();

为(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帧的高清视频需要巨大的处理能力。


Im trying to send a lot of desktop captured images to an encoders (FFmpeg) stdin.

The following code example works.

the CaptureScreen() function provides an image in 5-10 ms.

If I save the image in a MemoryStream it takes almost no time.

But I can only save 1 image every 45 ms to 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());
}

The question is:

Can I do the saving process faster?

I try to get stable 60 fps this way

解决方案

The bottleneck here is that ffmpeg reads data at the same speed it compresses it to .avi, which is slow. So your img.Save method blocks until there is some space in the stream's buffer to write its data.

There is not much you can do. Compressing 60 fps HD video in real time require a huge processing power.

这篇关于更快的写入图像Process.StandardInput.BaseStream方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆