第一次打开后Dxsnap无法正确显示视频 [英] Dxsnap not displaying the video properly after first time open

查看:123
本文介绍了第一次打开后Dxsnap无法正确显示视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 DirectShowLib-2005 - DxSnap 示例显示和捕获来自网络摄像头的图像。



但是,当我尝试将其与我的应用程序合并时(我试图从我的主表单中调用该表单),它第一次起作用。一旦我关闭并打开捕获窗口,它就无法正确显示视频。

但是捕获图像的过程一直很完美。

I am using DirectShowLib-2005 - DxSnap example to display and capture the image from Webcam.
Everything works fine with the example.
But when i try to merge it with my application (i tried to call that form from my main form) it is working for the first time. Once i close and open the capture window, it is not displaying the video properly.
But the capturing of the image works perfectly all the time.

 public partial class frmMain : Form
{
    public frmMain()
    {
        InitializeComponent();
    }


    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    private static void Main()
    {
        Application.Run(new frmMain());
    }

    private void button1_Click(object sender, EventArgs e)
    {
        frmdxSnap frmdxSnap = new frmdxSnap();
        frmdxSnap.ShowDialog(this);
    }
}

即使重新启动PC后,它也保持不变。

我没有更改DxSnap表单中的任何内容。

Even after restarting the PC, its still the same.
I have not changed anything in the DxSnap form.

推荐答案

虽然 DxSnap 是一个很好的入门示例,但它可以节省很多的角落使上述文物成为可能。问题在于以下行中的假设:

While DxSnap is a good introductory sample, it cuts a couple of corners making artifacts like mentioned possible. The problem is the assumption this in the following line:

m_stride = m_videoWidth *(videoInfoHeader.BmiHeader.BitCount / 8);

实际步幅可能有所不同,这是视频硬件的众所周知效果,表明步幅有所提高。从Sample Grabber缓冲区复制图像时,将步幅重新计算为 BufferLen / m_videoHeight 会更准确(请参见下面的代码段;也请注意此处的断言-大概是您忽略它或运行Release版本)。最好只是检查当前的媒体类型并从那里获取大步。

Actual stride might be different and it's a well known effect of video hardware suggesting increased strides. When you copy image from Sample Grabber buffer, it would be more accurate to re-compute stride as BufferLen / m_videoHeight (see code snippet below; also note assertion there -- presumably you are ignoring it or running Release builds). It would be even better to simply check current media type and obtain stride from there.

您可能没有视频管道的第一个实例的问题,因为它可能正在使用视频覆盖和不同的代码路径。完全对齐的帧大小(宽度)(例如640、1024等)可能根本没有问题。

You might be not having the problem with first instance of video pipeline since it might be using video overlay and different code path. You might have no issue at all with well-aligned frame sizes (widths) like 640, 1024 etc.

/// <summary> buffer callback, COULD BE FROM FOREIGN THREAD. </summary>
int ISampleGrabberCB.BufferCB( double SampleTime, IntPtr pBuffer, int BufferLen )
{
    // Note that we depend on only being called once per call to Click.  Otherwise
    // a second call can overwrite the previous image.
    Debug.Assert(BufferLen == Math.Abs(m_stride) * m_videoHeight, "Incorrect buffer length");

    if (m_WantOne)
    {
        m_WantOne = false;
        Debug.Assert(m_ipBuffer != IntPtr.Zero, "Unitialized buffer");

        // Save the buffer
        CopyMemory(m_ipBuffer, pBuffer, BufferLen);
        ////////////////////////////////////////////
        // HOTFIX: Let's have the stride re-computed for the case it was changed dynamically or otherwise
        m_stride = BufferLen / m_videoHeight;
        ////////////////////////////////////////////

        // Picture is ready.
        m_PictureReady.Set();
    }

    return 0;
}

这篇关于第一次打开后Dxsnap无法正确显示视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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