public void SetupFileRecorderGraph(DsDevice dev, SystemCodecEntry compressor, ref float iFrameRate, ref int iWidth, ref int iHeight, string fileName) { try { SetupGraphInternal(dev, compressor, ref iFrameRate, ref iWidth, ref iHeight, fileName); latestBitmap = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb); fullRect = new Rectangle(0, 0, latestBitmap.Width, latestBitmap.Height); } catch { CloseResources(); throw; } }
private void SetupGraphInternal(DsDevice dev, SystemCodecEntry compressor, ref float iFrameRate, ref int iWidth, ref int iHeight, string fileName) { filterGraph = (IFilterGraph2)new FilterGraph(); mediaCtrl = filterGraph as IMediaControl; capBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2(); samplGrabber = (ISampleGrabber)new SampleGrabber(); int hr = capBuilder.SetFiltergraph(filterGraph); DsError.ThrowExceptionForHR(hr); if (rot != null) { rot.Dispose(); rot = null; } rot = new DsROTEntry(filterGraph); if (fileName != null) { if (compressor.Codec == SupportedCodec.Uncompressed || compressor.Codec == SupportedCodec.DV) { deviceFilter = BuildFileCaptureGraph_UncompressedOrDV(dev, compressor.Device, fileName); } else if (compressor.Codec == SupportedCodec.XviD || compressor.Codec == SupportedCodec.HuffYuv211 || compressor.Codec == SupportedCodec.Unsupported) { deviceFilter = BuildFileCaptureGraph_WithCodec(dev, compressor.Device, fileName); } } else { deviceFilter = BuildPreviewOnlyCaptureGraph(dev); } if (deviceFilter != null) // If any of the default config items are set SetConfigParms(capBuilder, deviceFilter, ref iFrameRate, ref iWidth, ref iHeight); // Now that sizes are fixed/known, store the sizes SaveSizeInfo(samplGrabber); }
public void ReloadSettings() { if (IsConnected && (videoInputDevice != null || videoCompressor != null)) { DsDevice inputDevice; SystemCodecEntry compressor; FindInputAndCompressorToUse(out inputDevice, out compressor); bool reconnect = false; if (inputDevice != null && videoInputDevice != null && videoInputDevice.DevicePath != inputDevice.DevicePath) { // We have a new video device. Will need to reconnect to it reconnect = true; } if (compressor != null && videoCompressor != null && videoCompressor.Codec != compressor.Codec) { // We have a new compressor device. Will need to reconnect reconnect = true; } if (reconnect) { EnsureDisconnected(); videoInputDevice = inputDevice; videoCompressor = compressor; EnsureConnected(); } } }
private void FindInputAndCompressorToUse(out DsDevice inputDevice, out SystemCodecEntry compressor) { inputDevice = null; compressor = null; List<DsDevice> allInputDevices = new List<DsDevice>(DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)); if (!string.IsNullOrEmpty(DriverSettings.Instance.DeviceName)) inputDevice = allInputDevices.FirstOrDefault(x => x.Name == DriverSettings.Instance.DeviceName); else if (allInputDevices.Count > 0) inputDevice = allInputDevices[0]; compressor = VideoCodecs.GetSupportedVideoCodec(DriverSettings.Instance.CompressorDevice); }
// From DirectShowNet Forums: http://sourceforge.net/p/directshownet/discussion/460697/thread/edb37d2a/ // ---------------------------------------------------------------------------------------------------------------- // The ugly truth is that some people who have written codecs have done a lousy job of it, and they barely work. // Some codecs are complex and need special handling. A generic program to work with all codecs is probably impossible. // And if it were possible, it would be so complex that it would be a failure as a sample, since no one would be able // to read the code and figure out how it worked (which is what samples are for). // ------------------------------------------------------------------------------------------------------------------ // It also appears that if the application is not built as x86 it will not display a whole bunch of codecs on 64bit machines // http://social.msdn.microsoft.com/Forums/en-US/windowsdirectshowdevelopment/thread/d9029891-25e5-4ed1-ab31-9cae7c6c8eae/ // There is not much we can do here other than making sure the build is always x86 public static List<SystemCodecEntry> GetSupportedVideoCodecs() { var supportedCodecs = new List<SystemCodecEntry>(); var allCodecs = new List<DsDevice>(); allCodecs.AddRange(DsDevice.GetDevicesOfCat(FilterCategory.VideoCompressorCategory)); foreach (SupportedCodec codec in Enum.GetValues(typeof (SupportedCodec))) { if (codec == SupportedCodec.Unsupported) continue; var entry = new SystemCodecEntry { Codec = codec }; entry.Device = allCodecs.FirstOrDefault(x => x.Name == entry.DeviceName); supportedCodecs.Add(entry); } return supportedCodecs; }