Tôi đang cố gắng gửi rất nhiều ảnh chụp màn hình đến bộ mã hóa (FFmpeg) stdin.Cách nhanh hơn để ghi hình ảnh vào Process.StandardInput.BaseStream
Ví dụ mã sau hoạt động.
chức năng CaptureScreen()
cung cấp hình ảnh trong 5-10 mili giây.
Nếu tôi lưu hình ảnh trong MemoryStream, hầu như không mất thời gian.
Nhưng tôi chỉ có thể lưu 1 hình ảnh mỗi 45 ms đến 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());
}
Câu hỏi đặt ra là:
Tôi có thể làm quá trình tiết kiệm nhanh hơn?
tôi cố gắng để có được ổn định 60 fps cách này
Bạn đã thử sử dụng 'ImageFormat.png' sao cho số lượng dữ liệu thực tế được đọc/ghi bị giảm? – PhonicUK
Tôi đã thử nó. Nó thậm chí còn chậm hơn ... như 130 ms – Hasibii