首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用AForge.Video.FFMPEG / AForge.Video.VFW的屏幕截取视频.帧速率问题

使用AForge.Video.FFMPEG / AForge.Video.VFW的屏幕截取视频.帧速率问题
EN

Stack Overflow用户
提问于 2012-04-26 23:06:24
回答 1查看 9.8K关注 0票数 5

我的WinForms .NET 4 C#应用程序在用户与桌面交互时记录桌面。

它根据系统的速度使用AForge FFMPEG或VFW包装器。当然,捕获是在后台线程中完成的。

在这两种情况下,包装都要求预先指定帧速率。这是有问题的,因为捕获频率是不确定的,并且很容易受到目标机器的繁忙程度的影响。在一个好的系统中,我最多可以得到10个FPS。

这里有两个问题:

  • 如何根据实际捕获帧速率对齐帧?
  • 如何提高帧速率,也许可以使用AForge?

以外的解决方案。

为了清楚起见,下面列出了我使用的代码:

代码语言:javascript
复制
private void ThreadWork ()  
{  
    int count = 0;  
    string filename = "";  
    RECT rect = new RECT();  
    System.Drawing.Bitmap bitmap = null;  
    System.Drawing.Graphics graphics = null;  
    System.DateTime dateTime = System.DateTime.Now;  
    System.IntPtr hWndForeground = System.IntPtr.Zero;  
    AForge.Video.FFMPEG.VideoFileWriter writer = null;  

    filename = @"c:\Users\Raheel Khan\Desktop\Temp\Capture.avi";
    if (System.IO.File.Exists(filename))
        System.IO.File.Delete(filename);

    writer = new AForge.Video.FFMPEG.VideoFileWriter();
    writer.Open
    (
        filename,
        System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
        System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height,
        10, // FPS
        AForge.Video.FFMPEG.VideoCodec.MPEG4
    );

    bitmap = new Bitmap
    (
        System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
        System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height,
        System.Drawing.Imaging.PixelFormat.Format24bppRgb
    );
    graphics = System.Drawing.Graphics.FromImage(bitmap);

    dateTime = System.DateTime.Now;

    while (System.DateTime.Now.Subtract(dateTime).TotalSeconds < 10) // 10 seconds.
    {
        graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size);

        rect = new RECT();
        hWndForeground = GetForegroundWindow();
        GetWindowRect(hWndForeground, ref rect);
        graphics.DrawRectangle(Pens.Red, rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
        graphics.DrawString(count++.ToString(), this.Font, Brushes.Red, 10, 10);

        writer.WriteVideoFrame(bitmap);

        System.Threading.Thread.Sleep(10);
    }

    writer.Close();
    writer.Dispose();

    System.Diagnostics.Process.Start(System.IO.Path.GetDirectoryName(filename));
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-27 16:25:20

您可以将帧捕获到临时文件夹( jpegs )或mjpeg文件中,然后在用户需要时将其重新处理为avi视频文件。这将减少你需要做的‘飞行’的处理量和释放资源-并允许你的系统达到一个更高和更有规律的帧速率。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10342647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档