public void Initialize(int deviceNum) { if (firstActive) { return; } firstActive = true; if (!DsUtils.IsCorrectDirectXVersion()) { return; } if (!DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices)) { return; } DsDevice dev = null; if (capDevices.Count >= 1) { dev = capDevices[deviceNum] as DsDevice; } if (dev == null) { return; } StartupVideo(dev.Mon); }
public VideoInfoHeader StartProvider(bool preview, ISampleGrabberCB samplegrabber, IntPtr owner) { int hr; VideoInfoHeader rv; try { if (!DsUtils.IsCorrectDirectXVersion()) { throw new Exception("At least DirectX 8.1 is required!"); } if (!DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices)) { throw new Exception("Could not retrieve the list of capture devices!"); } if (capDevices.Count == 0) { throw new Exception("Capture Sample Provider is not applicable!"); } DsDevice device = null; if (capDevices.Count == 1) { device = capDevices[0] as DsDevice; } else { DeviceSelector selector = new DeviceSelector(capDevices); selector.ShowDialog(); device = selector.SelectedDevice; } if (device == null) { throw new Exception("No video capture device could be selected!"); } CreateCaptureDevice(device.Mon); GetInterfaces(); rv = SetupGraph(preview, samplegrabber); SetupVideoWindow(owner); hr = mediaCtrl.Run(); if (hr < 0) { Marshal.ThrowExceptionForHR(hr); } } catch (Exception ee) { throw new Exception("Could not start video stream\r\n" + ee.Message); } return(rv); }
/// <summary> detect first form appearance, start grabber. </summary> //private void MainForm_Activated(object sender, System.EventArgs e) private void mainformactive() { if (firstActive) { return; } firstActive = true; if (!DsUtils.IsCorrectDirectXVersion()) { MessageBox.Show(this, "DirectX 8.1 NOT installed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.Left = 2000; timer1.Enabled = true; //value = 2; return; } if (!DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices)) { MessageBox.Show(this, "No video capture devices found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.Left = 2000; timer1.Enabled = true; //value = 2; return; } DsDevice dev = null; if (capDevices.Count == 1) { dev = capDevices[0] as DsDevice; } else { DeviceSelector selector = new DeviceSelector(capDevices); selector.ShowDialog(this); dev = selector.SelectedDevice; } if (dev == null) { //this.Close(); this.Left = 2000; timer1.Enabled = true; //value = 2; return; } if (!StartupVideo(dev.Mon)) { //{ this.Close(); //return; this.Left = 2000; timer1.Enabled = true; //value = 2; return; } }
void Initialize() { if (firstActive) { throw new VideoGrabberException("已經呼叫過 BeginGrabber() 方法了!"); } firstActive = true; if (!DsUtils.IsCorrectDirectXVersion()) { EndGrabber(); throw new VideoGrabberException("系統未安裝 DirectX 8.1 以後的版本!"); } /* * //if( ! DsDevice.GetDevicesOfCat( FilterCategory.VideoInputDevice, out capDevices ) ) * if( (capDevices = DsDevice.GetDevicesOfCat( FilterCategory.VideoInputDevice )) == null ) * { * EndGrabber(); * throw new VideoGrabberException("未偵測到視訊裝置!"); * } * * DsDevice dev = null; * if( capDevices.Length == 1 ) * dev = capDevices[0] as DsDevice; * else * { * DeviceSelector selector = new DeviceSelector( capDevices ); * selector.ShowDialog( this ); * dev = selector.SelectedDevice; * } */ if (capDevice == null) { DeviceSelector selector = new DeviceSelector( ); if (selector.Devices.Length > 1) { selector.ShowDialog(this); } capDevice = selector.SelectedDevice; if (capDevice == null) { EndGrabber(); throw new VideoGrabberException("無法取得視訊裝置!"); } } if (!StartupVideo(capDevice.Mon)) { EndPreview(); EndGrabber(); throw new VideoGrabberException("無法初始化設定視訊裝置!"); } }
/// <summary> detect first form appearance, start capturing. </summary> private void MainForm_Activated(object sender, System.EventArgs e) { if (firstActived) { return; } firstActived = true; if (!DsUtils.IsCorrectDirectXVersion()) { MessageBox.Show(this, "DirectX 8.1 or higher NOT installed!", "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.Close(); return; } if (!DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices)) { MessageBox.Show(this, "No video capture devices found!", "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.Close(); return; } SaveFileDialog sd = new SaveFileDialog(); sd.FileName = @"MotionCapture.avi"; sd.Title = "Save Video Stream as..."; sd.Filter = "Video file (*.avi)|*.avi"; sd.FilterIndex = 1; if (sd.ShowDialog() != DialogResult.OK) { this.Close(); return; } fileName = sd.FileName; DsDevice dev = null; if (capDevices.Count == 1) { dev = capDevices[0] as DsDevice; } else { DeviceSelector selector = new DeviceSelector(capDevices); selector.ShowDialog(this); dev = selector.SelectedDevice; } if (dev == null) { this.Close(); return; } if (!StartupVideo(dev.Mon)) { this.Close(); } this.Text += " - capturing -"; }
public bool StartCamera() { if (firstActive) { return(false); } firstActive = true; if (!DsUtils.IsCorrectDirectXVersion()) { System.Windows.Forms.MessageBox.Show("DirectX 8.1 NOT installed!", "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (!DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices)) { System.Windows.Forms.MessageBox.Show("No video capture devices found!", "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.Close(); return(false); } //SaveFileDialog sd = new SaveFileDialog(); //sd.FileName = @"CaptureNET.avi"; //sd.Title = "Save Video Stream as..."; //sd.Filter = "Video file (*.avi)|*.avi"; //sd.FilterIndex = 1; //if (sd.ShowDialog() != DialogResult.OK) //{ this.Close(); return false; } fileName = "c:\\a.avi"; DsDevice dev = null; //if (capDevices.Count == 1) // dev = capDevices[0] as DsDevice; //else //{ // DeviceSelector selector = new DeviceSelector(capDevices); // selector.ShowDialog(this); // dev = selector.SelectedDevice; //} dev = capDevices[1]; if (dev == null) { this.Close(); return(false); } if (!StartupVideo(dev.Mon)) { this.Close(); } return(true); }
void Initialize() { if (firstActive) { throw new VideoGrabberException("已經呼叫過 BeginGrabber() 方法了!"); } firstActive = true; if (!DsUtils.IsCorrectDirectXVersion()) { EndGrabber(); throw new VideoGrabberException("系統未安裝 DirectX 8.1 以後的版本!"); } if (capDevice == null) { if ((capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)) == null) { EndGrabber(); throw new VideoGrabberException("未偵測到視訊裝置!"); } if (capDevices.Length >= 1) { capDevice = capDevices[0] as DsDevice; } else { DeviceSelector selector = new DeviceSelector(); selector.ShowDialog(this); capDevice = selector.SelectedDevice; } } if (capDevice == null) { EndGrabber(); throw new VideoGrabberException("無法取得視訊裝置!"); } if (!StartupVideo(capDevice.Mon)) { EndGrabber(); throw new VideoGrabberException("無法初始化設定視訊裝置!"); } grabberThread = new Thread(new ThreadStart(Processing)); }
/// <summary> detect first form appearance, start grabber. </summary> private void MainForm_Activated(object sender, System.EventArgs e) { if (firstActive) { return; } firstActive = true; if (!DsUtils.IsCorrectDirectXVersion()) { MessageBox.Show(this, "DirectX 8.1 NOT installed!", "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.Close(); return; } if (!DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices)) { MessageBox.Show(this, "No video capture devices found!", "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.Close(); return; } DsDevice dev = null; if (capDevices.Count == 1) { dev = capDevices[0] as DsDevice; } else { DeviceSelector selector = new DeviceSelector(capDevices); selector.ShowDialog(this); dev = selector.SelectedDevice; } if (dev == null) { this.Close(); return; } if (!StartupVideo(dev.Mon)) { this.Close(); } }
public static DsDevice[] GetDevices() { ArrayList devices; if (!DsUtils.IsCorrectDirectXVersion()) { _logger.Error("DirectX 8.1 NOT installed!"); devices = new ArrayList(); // throw new Exception("DirectX 8.1 NOT installed!"); } if (!DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out devices)) { //throw new Exception("No video capture devices found!"); _logger.Error("No video capture devices found!"); devices = new ArrayList(); } return((DsDevice[])devices.ToArray(typeof(DsDevice))); }
public void Capture_video() { if (firstActive) { firstActive = true; CloseInterfaces(); //this.Close(); return; } firstActive = true; if (!DsUtils.IsCorrectDirectXVersion()) { MessageBox.Show(this, "DirectX 8.1 NOT installed!", "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.Close(); return; } if (!DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices)) { MessageBox.Show(this, "No video capture devices found!", "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.Close(); return; } SaveFileDialog sd = new SaveFileDialog(); sd.FileName = DateTime.Now.ToString("yyMMdd hh-mm-ss"); sd.Title = "Save Video Stream as..."; sd.Filter = "Video file (*.avi)|*.avi"; sd.FilterIndex = 1; sd.InitialDirectory = "C:\\temp\\autobot7\\"; Thread.Sleep(2000); System.Windows.Forms.SendKeys.Send("{ENTER}"); if (sd.ShowDialog() != DialogResult.OK) { this.Close(); return; } fileName = sd.FileName; DsDevice dev = null; if (capDevices.Count == 1) { dev = capDevices[0] as DsDevice; } else { DeviceSelector selector = new DeviceSelector(capDevices); selector.ShowDialog(this); dev = selector.SelectedDevice; } if (dev == null) { this.Close(); return; } if (!StartupVideo(dev.Mon)) { this.Close(); } this.Text = "save" + fileName + ".........."; }
public void InitVideoCapture(int videoDeviceID, FrameRate framerate, Resolution resolution, ImageFormat format, bool grayscale) { if (cameraInitialized) { return; } this.resolution = resolution; this.grayscale = grayscale; this.frameRate = framerate; this.videoDeviceID = videoDeviceID; this.format = format; switch (resolution) { case Resolution._160x120: cameraWidth = 160; cameraHeight = 120; break; case Resolution._320x240: cameraWidth = 320; cameraHeight = 240; break; case Resolution._640x480: cameraWidth = 640; cameraHeight = 480; break; case Resolution._800x600: cameraWidth = 800; cameraHeight = 600; break; case Resolution._1024x768: cameraWidth = 1024; cameraHeight = 768; break; case Resolution._1280x1024: cameraWidth = 1280; cameraHeight = 1024; break; case Resolution._1600x1200: cameraWidth = 1600; cameraHeight = 1200; break; } if (!DsUtils.IsCorrectDirectXVersion()) { throw new GoblinException("DirectX 8.1 NOT installed!"); } if (!DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices)) { throw new GoblinException("No video capture devices found!"); } DsDevice dev = null; if (videoDeviceID >= capDevices.Count) { String suggestion = "Try the following device IDs:"; for (int i = 0; i < capDevices.Count; i++) { suggestion += " " + i + ":" + ((DsDevice)capDevices[i]).Name + ", "; } throw new GoblinException("VideoDeviceID " + videoDeviceID + " is out of the range. " + suggestion); } dev = (DsDevice)capDevices[videoDeviceID]; selectedVideoDeviceName = ((DsDevice)capDevices[videoDeviceID]).Name; if (dev == null) { throw new GoblinException("This video device cannot be accessed"); } StartupVideo(dev.Mon); cameraInitialized = true; }
/// <summary> detect first form appearance, start grabber. </summary> /// <fixme> There are three paths to activation: /// One opens a media file whose name is specified in the dsshost.exe.config file, /// another assumes that a particular video card is present, /// and the third asks the user to select a video input source. /// This module really only works for the first two paths. /// </fixme> public void Activate() { IMoniker moniker; IMoniker devmoniker; if (firstActive) { return; } firstActive = true; if (!DsUtils.IsCorrectDirectXVersion()) { LogInfo(LogGroups.Console, "DirectX 8.1 NOT installed!"); //this.Close(); return; } try { if (videoSource.Equals("File", StringComparison.CurrentCultureIgnoreCase)) { LogInfo(LogGroups.Console, "File to play : " + filePath); //capFilter = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.WM_ASF_Reader); } else if (videoSource.Equals("Analog", StringComparison.CurrentCultureIgnoreCase)) { atiCrossbar = (IBaseFilter)DsDev.CreateFromMoniker(ATICrossbar); capFilter = (IBaseFilter)DsDev.CreateFromMoniker(ATICapture); atiTVCardFound = true; } else // digital camera, may be a webcam { if (!DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices)) { LogInfo(LogGroups.Console, "No video capture devices found!"); return; } if (capDevices.Count == 1) { dev = capDevices[0] as DsDevice; } else { //DeviceSelector selector = new DeviceSelector(capDevices); //selector.ShowDialog(); //dev = selector.SelectedDevice; dev = capDevices[0] as DsDevice; } if (dev == null) { LogInfo(LogGroups.Console, "Cannot use first capture device found."); return; } CreateCaptureDevice(dev.Mon); } StartupVideo(); } catch (Exception ex) { LogInfo(LogGroups.Console, "Filter Graph can't start : " + ex.Message); } }