如何列出相机可用的视频分辨率

发布于 2024-12-05 13:45:49 字数 241 浏览 0 评论 0原文

如果我的电脑上连接了多个摄像头...我想知道特定摄像头的最佳可用分辨率...

例如某些摄像头是高清或全高清(1,280×720 像素 (720p) 或 1,920×1,080 像素) (1080i/1080p))或最常见的是网络摄像头......

我想至少知道摄像头正常工作的最佳视频模式......(摄像头工作的模式)

我的工作是使用 C# 进行 WPF(我正在使用 Directshow),

提前致谢

if I have more than one camera attached to my PC ... I want to know the best available resolutions for a specific camera ...

for example some cameras are HD or FullHD (1,280×720 pixels (720p) or 1,920×1,080 pixels (1080i/1080p)) or the most common are web cameras....

I want to know at least the best video mode that the camera work properly...(the mode that the camera made to work with)

my work is on WPF using C# (I am using Directshow)

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

送你一个梦 2024-12-12 13:45:49

这是我编写的代码,它非常适合我

public static List<Point> GetAllAvailableResolution(DsDevice vidDev)
{
    try
    {
        int hr;
        int max = 0;
        int bitCount = 0;
        IBaseFilter sourceFilter = null;
        var m_FilterGraph2 = new FilterGraph() as IFilterGraph2;
        hr = m_FilterGraph2.AddSourceFilterForMoniker(vidDev.Mon, null, vidDev.Name, out sourceFilter);
        var pRaw2 = DsFindPin.ByCategory(sourceFilter, PinCategory.Capture, 0);
        var AvailableResolutions = new List<Point>();
        VideoInfoHeader v = new VideoInfoHeader();
        IEnumMediaTypes mediaTypeEnum;
        hr = pRaw2.EnumMediaTypes(out mediaTypeEnum);
        AMMediaType[] mediaTypes = new AMMediaType[1];
        IntPtr fetched = IntPtr.Zero;
        hr = mediaTypeEnum.Next(1, mediaTypes, fetched);

        while (fetched != null && mediaTypes[0] != null)
        {
            Marshal.PtrToStructure(mediaTypes[0].formatPtr, v);
            if (v.BmiHeader.Size != 0 && v.BmiHeader.BitCount != 0)
            {
                if (v.BmiHeader.BitCount > bitCount)
                {
                    AvailableResolutions.Clear();
                    max = 0;
                    bitCount = v.BmiHeader.BitCount;
                }
                AvailableResolutions.Add(new Point(v.BmiHeader.Width, v.BmiHeader.Height));
                if (v.BmiHeader.Width > max || v.BmiHeader.Height > max)
                    max = (Math.Max(v.BmiHeader.Width, v.BmiHeader.Height));
            }
            hr = mediaTypeEnum.Next(1, mediaTypes, fetched);
        }
        return AvailableResolutions;
    }

    catch (Exception ex)
    {
        Log(ex);
        return new List<Point>();
    }
}

(例如,可以将其添加到 WPF-MediaKit 中的 VideoCaptureElement 中)

This is a code that I wrote, its working perfectly for me

public static List<Point> GetAllAvailableResolution(DsDevice vidDev)
{
    try
    {
        int hr;
        int max = 0;
        int bitCount = 0;
        IBaseFilter sourceFilter = null;
        var m_FilterGraph2 = new FilterGraph() as IFilterGraph2;
        hr = m_FilterGraph2.AddSourceFilterForMoniker(vidDev.Mon, null, vidDev.Name, out sourceFilter);
        var pRaw2 = DsFindPin.ByCategory(sourceFilter, PinCategory.Capture, 0);
        var AvailableResolutions = new List<Point>();
        VideoInfoHeader v = new VideoInfoHeader();
        IEnumMediaTypes mediaTypeEnum;
        hr = pRaw2.EnumMediaTypes(out mediaTypeEnum);
        AMMediaType[] mediaTypes = new AMMediaType[1];
        IntPtr fetched = IntPtr.Zero;
        hr = mediaTypeEnum.Next(1, mediaTypes, fetched);

        while (fetched != null && mediaTypes[0] != null)
        {
            Marshal.PtrToStructure(mediaTypes[0].formatPtr, v);
            if (v.BmiHeader.Size != 0 && v.BmiHeader.BitCount != 0)
            {
                if (v.BmiHeader.BitCount > bitCount)
                {
                    AvailableResolutions.Clear();
                    max = 0;
                    bitCount = v.BmiHeader.BitCount;
                }
                AvailableResolutions.Add(new Point(v.BmiHeader.Width, v.BmiHeader.Height));
                if (v.BmiHeader.Width > max || v.BmiHeader.Height > max)
                    max = (Math.Max(v.BmiHeader.Width, v.BmiHeader.Height));
            }
            hr = mediaTypeEnum.Next(1, mediaTypes, fetched);
        }
        return AvailableResolutions;
    }

    catch (Exception ex)
    {
        Log(ex);
        return new List<Point>();
    }
}

(E.g. this can be added to VideoCaptureElement in WPF-MediaKit)

寄风 2024-12-12 13:45:49

我用它来获得最大框架尺寸,只需更改以满足您的需求;)

private Point GetMaxFrameSize(IPin pStill)
    {
        VideoInfoHeader v;

        IAMStreamConfig videoStreamConfig = pStill as IAMStreamConfig;

        int iCount = 0, iSize = 0;
        videoStreamConfig.GetNumberOfCapabilities(out iCount, out iSize);

        IntPtr TaskMemPointer = Marshal.AllocCoTaskMem(iSize);

        int iMaxHeight = 0;
        int iMaxWidth = 0;

        for (int iFormat = 0; iFormat < iCount; iFormat++)
        {
            AMMediaType pmtConfig = null;
            IntPtr ptr = IntPtr.Zero;

            videoStreamConfig.GetStreamCaps(iFormat, out pmtConfig, TaskMemPointer);

            v = (VideoInfoHeader)Marshal.PtrToStructure(pmtConfig.formatPtr, typeof(VideoInfoHeader));
            if (v.BmiHeader.Width > iMaxWidth)
            {
                iMaxWidth = v.BmiHeader.Width;
                iMaxHeight = v.BmiHeader.Height;
            }
            DsUtils.FreeAMMediaType(pmtConfig);

        }

        Marshal.FreeCoTaskMem(TaskMemPointer);


        return new Point(iMaxWidth, iMaxHeight);
    }


    /// <summary>
    ///  Free the nested structures and release any
    ///  COM objects within an AMMediaType struct.
    /// </summary>
    public static void FreeAMMediaType(AMMediaType mediaType)
    {
        if (mediaType != null)
        {
            if (mediaType.formatSize != 0)
            {
                Marshal.FreeCoTaskMem(mediaType.formatPtr);
                mediaType.formatSize = 0;
                mediaType.formatPtr = IntPtr.Zero;
            }
            if (mediaType.unkPtr != IntPtr.Zero)
            {
                Marshal.Release(mediaType.unkPtr);
                mediaType.unkPtr = IntPtr.Zero;
            }
        }
    }

i use this to get max frame size, just change to suit your needs ;)

private Point GetMaxFrameSize(IPin pStill)
    {
        VideoInfoHeader v;

        IAMStreamConfig videoStreamConfig = pStill as IAMStreamConfig;

        int iCount = 0, iSize = 0;
        videoStreamConfig.GetNumberOfCapabilities(out iCount, out iSize);

        IntPtr TaskMemPointer = Marshal.AllocCoTaskMem(iSize);

        int iMaxHeight = 0;
        int iMaxWidth = 0;

        for (int iFormat = 0; iFormat < iCount; iFormat++)
        {
            AMMediaType pmtConfig = null;
            IntPtr ptr = IntPtr.Zero;

            videoStreamConfig.GetStreamCaps(iFormat, out pmtConfig, TaskMemPointer);

            v = (VideoInfoHeader)Marshal.PtrToStructure(pmtConfig.formatPtr, typeof(VideoInfoHeader));
            if (v.BmiHeader.Width > iMaxWidth)
            {
                iMaxWidth = v.BmiHeader.Width;
                iMaxHeight = v.BmiHeader.Height;
            }
            DsUtils.FreeAMMediaType(pmtConfig);

        }

        Marshal.FreeCoTaskMem(TaskMemPointer);


        return new Point(iMaxWidth, iMaxHeight);
    }


    /// <summary>
    ///  Free the nested structures and release any
    ///  COM objects within an AMMediaType struct.
    /// </summary>
    public static void FreeAMMediaType(AMMediaType mediaType)
    {
        if (mediaType != null)
        {
            if (mediaType.formatSize != 0)
            {
                Marshal.FreeCoTaskMem(mediaType.formatPtr);
                mediaType.formatSize = 0;
                mediaType.formatPtr = IntPtr.Zero;
            }
            if (mediaType.unkPtr != IntPtr.Zero)
            {
                Marshal.Release(mediaType.unkPtr);
                mediaType.unkPtr = IntPtr.Zero;
            }
        }
    }
べ映画 2024-12-12 13:45:49

根据这个网页:
http://www.e-consystems.com/blog/camera/?p =651,您应该使用此调用来获取此设备的功能:

g_DShowCaptureGraph.GetNumberOfCapabilities(nStream, &iCount, &iSize);
g_DShowCaptureGraph.GetStreamCaps(nStream,iFormat, &pmtConfig, (BYTE*)&scc);

但是,它们是 C++。

According to this webpage:
http://www.e-consystems.com/blog/camera/?p=651, you should use this call for getting the capabilities of this device:

g_DShowCaptureGraph.GetNumberOfCapabilities(nStream, &iCount, &iSize);
g_DShowCaptureGraph.GetStreamCaps(nStream,iFormat, &pmtConfig, (BYTE*)&scc);

They are C++, however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文