// Set the Framerate, and video size private void SetConfigParms(DirectShowLib.ICaptureGraphBuilder2 capGraph, DirectShowLib.IBaseFilter capFilter, int iFrameRate, int iWidth, int iHeight) { int hr; object o; DirectShowLib.AMMediaType media; // Find the stream config interface hr = capGraph.FindInterface( DirectShowLib.PinCategory.Capture, DirectShowLib.MediaType.Video, capFilter, typeof(DirectShowLib.IAMStreamConfig).GUID, out o); DirectShowLib.IAMStreamConfig videoStreamConfig = o as DirectShowLib.IAMStreamConfig; if (videoStreamConfig == null) { throw new Exception("Failed to get IAMStreamConfig"); } // Get the existing format block hr = videoStreamConfig.GetFormat(out media); DsError.ThrowExceptionForHR(hr); // copy out the videoinfoheader DirectShowLib.VideoInfoHeader v = new DirectShowLib.VideoInfoHeader(); Marshal.PtrToStructure(media.formatPtr, v); // if overriding the framerate, set the frame rate if (iFrameRate > 0) { v.AvgTimePerFrame = 10000000 / iFrameRate; } // if overriding the width, set the width if (iWidth > 0) { v.BmiHeader.Width = iWidth; } // if overriding the Height, set the Height if (iHeight > 0) { v.BmiHeader.Height = iHeight; } // Copy the media structure back Marshal.StructureToPtr(v, media.formatPtr, false); // Set the new format hr = videoStreamConfig.SetFormat(media); DsError.ThrowExceptionForHR(hr); DirectShowLib.DsUtils.FreeAMMediaType(media); media = null; }