善良的白兰地 2017-03-23 03:07 采纳率: 0%
浏览 1009

directShow操作demo,获取视频信息时报错,尝试读取或写入受保护的内存

WinStructs.VIDEOINFOHEADER videoInfo = (WinStructs.VIDEOINFOHEADER)Marshal.PtrToStructure(mediaType.pbFormat, typeof(WinStructs.VIDEOINFOHEADER));
其中mediaType.pbFormat是获取到的视频指针,转换成WinStructs.VIDEOINFOHEADER结构体

WinStructs.VIDEOINFOHEADER为创建好的结构体内容如下:
public class WinStructs
{
///
/// The VIDEOINFOHEADER structure describes the bitmap and color information for a video image
///
[StructLayout(LayoutKind.Sequential)]
public struct VIDEOINFOHEADER
{
/// RECT structure that specifies the source video window. This structure can be a clipping rectangle, to select a portion of the source video stream.
public RECT rcSource;
/// RECT structure that specifies the destination video window.
public RECT rcTarget;
/// Approximate data rate of the video stream, in bits per second
public uint dwBitRate;
/// Data error rate, in bit errors per second
public uint dwBitErrorRate;
/// The desired average display time of the video frames, in 100-nanosecond units. The actual time per frame may be longer. See Remarks.
public long AvgTimePerFrame;
/// BITMAPINFOHEADER structure that contains color and dimension information for the video image bitmap. If the format block contains a color table or color masks, they immediately follow the bmiHeader member. You can get the first color entry by casting the address of member to a BITMAPINFO pointer
public BITMAPINFOHEADER bmiHeader;
}

    [StructLayout(LayoutKind.Sequential)]
    public struct RECT
    {
        int left;
        int top;
        int right;
        int bottom;
    }

    /// <summary>
    /// The BITMAPINFOHEADER structure contains information about the dimensions and color format of a device-independent bitmap (DIB). 
    /// SEE MSDN
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct BITMAPINFOHEADER
    {
        /// <summary>Specifies the number of bytes required by the structure. This value does not include the size of the color table or the size of the color masks, if they are appended to the end of structure. See Remarks.</summary>
        public uint biSize;
        /// <summary>Specifies the width of the bitmap, in pixels. For information about calculating the stride of the bitmap, see Remarks.</summary>
        public int biWidth;
        /// <summary>Specifies the height of the bitmap, in pixels. SEE MSDN</summary>
        public int biHeight;
        /// <summary>Specifies the number of planes for the target device. This value must be set to 1</summary>
        public ushort biPlanes;
        /// <summary>Specifies the number of bits per pixel (bpp).  For uncompressed formats, this value gives to the average number of bits per pixel. For compressed formats, this value gives the implied bit depth of the uncompressed image, after the image has been decoded.</summary>
        public ushort biBitCount;
        /// <summary>For compressed video and YUV formats, this member is a FOURCC code, specified as a DWORD in little-endian order. For example, YUYV video has the FOURCC 'VYUY' or 0x56595559. SEE MSDN</summary>
        public uint biCompression;
        /// <summary>Specifies the size, in bytes, of the image. This can be set to 0 for uncompressed RGB bitmaps</summary>
        public uint biSizeImage;
        /// <summary>Specifies the horizontal resolution, in pixels per meter, of the target device for the bitmap</summary>
        public int biXPelsPerMeter;
        /// <summary>Specifies the vertical resolution, in pixels per meter, of the target device for the bitmap</summary>
        public int biYPelsPerMeter;
        /// <summary>Specifies the number of color indices in the color table that are actually used by the bitmap. See Remarks for more information.</summary>
        public uint biClrUsed;
        /// <summary>Specifies the number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important</summary>
        public uint biClrImportant;
    }
}

请问哪位大神编一个这个关于视频获取指针的directShow操作demo,编译是可以通过,只是在获取视频信息时报错!网上查说是类型没有指定长度!可长度该怎么指定呢?请大神指教……

  • 写回答

1条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题