Represents a DirectShow filter (e.g. video capture device, compression codec).
To save a chosen filer for later recall save the MonikerString property on the filter:
string savedMonikerString = myFilter.MonikerString;
To recall the filter create a new Filter class and pass the string to the constructor:
Filter mySelectedFilter = new Filter( savedMonikerString );
Inheritance: IComparable
Esempio n. 1
0
        private void btnLigarCamera_Click(object sender, EventArgs e)
        {
            CamContainer = new DirectX.Capture.Filters();

            try
            {
                int no_of_cam = CamContainer.VideoInputDevices.Count;
                for (int i = 0; i < no_of_cam; i++)
                {
                    try
                    {
                        // obtém o dispositivo de entrada do vídeo
                        Camera = CamContainer.VideoInputDevices[i];
                        // inicializa a Captura usando o dispositivo
                        CaptureInfo = new DirectX.Capture.Capture(Camera, null);
                        // Define a janela de visualização do vídeo
                        CaptureInfo.PreviewWindow = pcCamera;
                        // Capturando o tratamento de evento
                        CaptureInfo.FrameCaptureComplete += AtualizaImagem;
                        // Captura o frame do dispositivo
                        CaptureInfo.CaptureFrame();
                        // Se o dispositivo foi encontrado e inicializado então sai sem checar o resto
                        break;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary> Populate the InnerList with a list of filters from a particular category </summary>
        protected void getFilters(Guid category)
        {
            int					hr;
            object				comObj = null;
            ICreateDevEnum		enumDev = null;
            UCOMIEnumMoniker	enumMon = null;
            UCOMIMoniker[]		mon = new UCOMIMoniker[1];

            try
            {
                // Get the system device enumerator
                Type srvType = Type.GetTypeFromCLSID( Clsid.SystemDeviceEnum );
                if( srvType == null )
                    throw new NotImplementedException( "System Device Enumerator" );
                comObj = Activator.CreateInstance( srvType );
                enumDev = (ICreateDevEnum) comObj;

                // Create an enumerator to find filters in category
                hr = enumDev.CreateClassEnumerator( ref category, out enumMon, 0 );
                if( hr != 0 )
                    throw new NotSupportedException( "No devices of the category" );

                // Loop through the enumerator
                int f;
                do
                {
                    // Next filter
                    hr = enumMon.Next( 1, mon, out f );
                    if( (hr != 0) || (mon[0] == null) )
                        break;

                    // Add the filter
                    Filter filter = new Filter( mon[0] );
                    InnerList.Add( filter );

                    // Release resources
                    Marshal.ReleaseComObject( mon[0] );
                    mon[0] = null;
                }
                while(true);

                // Sort
                InnerList.Sort();
            }
            finally
            {
                enumDev = null;
                if( mon[0] != null )
                    Marshal.ReleaseComObject( mon[0] ); mon[0] = null;
                if( enumMon != null )
                    Marshal.ReleaseComObject( enumMon ); enumMon = null;
                if( comObj != null )
                    Marshal.ReleaseComObject( comObj ); comObj = null;
            }
        }
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            foreach (Filter cam in _filters.VideoInputDevices)
            {
                if (cam.Name.Equals(cbCamera.SelectedItem.ToString()))
                    Camera = cam;
            }

            foreach (Filter mic in _filters.AudioInputDevices)
            {
                if (mic.Name.Equals(cbMicrophone.SelectedItem.ToString()))
                    Microphone = mic;
            }

            DialogResult = true;
            Close();
        }
Esempio n. 4
0
        public SpotRecorder(string fileDirectory, Filter recordingDevice)
        {
            if (!fileDirectory.Substring(fileDirectory.Length - 1, 1).Equals(@"\"))
            {
                this.FileDirectory = fileDirectory + @"\";
            }
            else
            {
                this.FileDirectory = fileDirectory;
            }

            this.RecordingDevice = recordingDevice;
            this.recorder = null;

            spotHandler = new SpotHandler(processName);
            spotHandler.TrackChanged += new SpotHandlerBase.TrackChangedEventHandler(spotHandler_TrackChanged);
        }
Esempio n. 5
0
        private void Form3_Load(object sender, EventArgs e)
        {
            CamContainer = new DirectX.Capture.Filters();
            try
            {
                int no_of_cam = CamContainer.VideoInputDevices.Count;

                for (int i = 0; i < no_of_cam; i++)
                {
                    try
                    {
                        // get the video input device
                        Camera = CamContainer.VideoInputDevices[i];

                        // initialize the Capture using the video input device
                        CaptureInfo = new DirectX.Capture.Capture(Camera, null);

                        // set the input video preview window
                        CaptureInfo.PreviewWindow = this.pictureBox1;

                        // Capturing complete event handler
                        CaptureInfo.FrameCaptureComplete += RefreshImage;

                        // Capture the frame from input device
                        CaptureInfo.CaptureFrame();

                        // if device found and initialize properly then exit without
                        // checking rest of input device
                        break;
                    }
                    catch (Exception ex) { }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
            }
        }
Esempio n. 6
0
		/// <summary> Populate the InnerList with a list of filters from a particular category </summary>
		protected void getFilters(Guid category)
		{
			int					hr;
			object				comObj = null;
			ICreateDevEnum		enumDev = null;
#if DSHOWNET
			IEnumMoniker	enumMon = null;
			IMoniker[]		mon = new IMoniker[1];
#else
#if VS2003
			UCOMIEnumMoniker	enumMon = null;
			UCOMIMoniker[]		mon = new UCOMIMoniker[1];
#else
			IEnumMoniker	enumMon = null;
			IMoniker[]		mon = new IMoniker[1];
#endif
#endif

			try 
			{
#if DSHOWNET
				// Get the system device enumerator
				Type srvType = Type.GetTypeFromCLSID( Clsid.SystemDeviceEnum );
				if( srvType == null )
					throw new NotImplementedException( "System Device Enumerator" );
				comObj = Activator.CreateInstance( srvType );
				enumDev = (ICreateDevEnum) comObj;

				// Create an enumerator to find filters in category
				hr = enumDev.CreateClassEnumerator( ref category, out enumMon, 0 );
#else
				enumDev = (ICreateDevEnum) new CreateDevEnum();

				// Create an enumerator to find filters in category
				hr = enumDev.CreateClassEnumerator( category, out enumMon, 0 );
#endif
				if( hr != 0 )
//#if NEWCODE
				{
					if(category == FilterCategory.VideoInputDevice)
					{
                        MessageBox.Show("Warning No Video Input Devices");
                        return;
						//throw new NotSupportedException( "No devices of the category VideoInputDevice" );
					}
					else if(category == FilterCategory.AudioInputDevice)
					{
//						throw new NotSupportedException( "No devices of the category AudioInputDevice" );
                        return;
					}
					else if(category == FilterCategory.VideoCompressorCategory)
					{
                        MessageBox.Show("Warning No Video Input Devices");
                        return;
                        //throw new NotSupportedException("No devices of the category VideoCompressorCategory");
					}
					else
						if(category == FilterCategory.AudioCompressorCategory)
					{
						throw new NotSupportedException( "No devices of the category AudioCompressorCategory" );
					}
					else
					{
						throw new NotSupportedException( "No devices of the category " + category.ToString() );
					}
				}
//#else
//				throw new NotSupportedException( "No devices of the category" );
//#endif

				// Loop through the enumerator
#if DSHOWNET
				IntPtr f = IntPtr.Zero;
#else
#if VS2003
				int f = 0;
#else
				IntPtr f = IntPtr.Zero;
#endif
#endif
				do
				{
					// Next filter
#if DSHOWNET
					hr = enumMon.Next( 1, mon, f );
#else
#if VS2003
					hr = enumMon.Next( 1, mon, out f );
#else
					hr = enumMon.Next( 1, mon, f );
#endif
#endif
					if( (hr != 0) || (mon[0] == null) )
						break;
					
					// Add the filter
					Filter filter = new Filter( mon[0] );
					InnerList.Add( filter );

					// Release resources
					Marshal.ReleaseComObject( mon[0] );
					mon[0] = null;
				}
				while(true);

				// Sort
				InnerList.Sort();
			}
			finally
			{
				enumDev = null;
				if( mon[0] != null )
					Marshal.ReleaseComObject( mon[0] ); mon[0] = null;
				if( enumMon != null )
					Marshal.ReleaseComObject( enumMon ); enumMon = null;
				if( comObj != null )
					Marshal.ReleaseComObject( comObj ); comObj = null;
			}
		}
Esempio n. 7
0
        // ------------- Constructors/Destructors --------------

		/// <summary> 
		///  Create a new Capture object. 
		///  videoDevice and audioDevice can be null if you do not 
		///  wish to capture both audio and video. However at least
		///  one must be a valid device. Use the <see cref="Filters"/> 
		///  class to list available devices.
		///  </summary>
		public Capture(Filter videoDevice, Filter audioDevice, bool audioViaPci)
        {
			if ( videoDevice == null && audioDevice == null )
				throw new ArgumentException( "The videoDevice and/or the audioDevice parameter must be set to a valid Filter.\n" );
			this.videoDevice = videoDevice;
			this.audioDevice = audioDevice;
			this.Filename = getTempFilename();
			this.AudioViaPci = audioViaPci;
            createGraph();
		}
Esempio n. 8
0
		// ------------- Constructors/Destructors --------------

		/// <summary> 
		///  Create a new Capture object. 
		///  videoDevice and audioDevice can be null if you do not 
		///  wish to capture both audio and video. However at least
		///  one must be a valid device. Use the <see cref="Filters"/> 
		///  class to list available devices.
		///  </summary>
		
		public Capture(Filter videoDevice, Filter audioDevice)
		{
			if ( videoDevice == null && audioDevice == null)
				throw new ArgumentException( "The videoDevice and/or the audioDevice parameter must be set to a valid Filter.\n" );
			this.videoDevice = videoDevice;
			this.audioDevice = audioDevice;
			this.Filename = getTempFilename();
			this.ImageCaptured = new System.Windows.Forms.PictureBox();
			createGraph(); 
		}
Esempio n. 9
0
 private void InitVideo()
 {
     this.filters = new Filters();
     if (this.filters.VideoInputDevices.Count > 0)
     {
         LoggingService.DebugFormatted("共检测到系统有{0}个视频设备...", new object[] { this.filters.VideoInputDevices.Count });
         this.videoDevice = this.filters.VideoInputDevices[this.filters.VideoInputDevices.Count - 1];
         this.capture = new DirectX.Capture.Capture(this.videoDevice, null);
         this.capture.FrameSize = new Size(640, 480);
         this.capture.PreviewWindow = this.pictureBox1;
         this.capture.RenderPreview();
     }
     else if (this.toolStripStatusLabel2 != null)
     {
         this.toolStripStatusLabel2.Text = "系统没有找到摄像头设备,你只能查看已经拍好的照片";
     }
 }
Esempio n. 10
0
 private void InitVideo()
 {
     this.filters = new Filters();
     if (this.filters.VideoInputDevices.Count > 0)
     {
         this.videoDevice = this.filters.VideoInputDevices[0];
     }
     if (this.filters.AudioInputDevices.Count > 0)
     {
         this.audioDevice = this.filters.AudioInputDevices[0];
     }
     this.capture = new DirectX.Capture.Capture(this.videoDevice, this.audioDevice);
     if (this.filters.VideoCompressors.Count > 0)
     {
         this.videoComprossor = this.filters.VideoCompressors[0];
         this.capture.VideoCompressor = this.videoComprossor;
     }
     this.capture.PreviewWindow = this.pictureBox1;
     this.capture.RenderPreview();
 }
Esempio n. 11
-1
        public VideoRecorder(Filter camera, Filter microphone)
        {       
            previewControl = new VideoPreview();
            filters = new Filters();

            capture = new Capture(camera, microphone);
            capture.VideoCompressor = filters.VideoCompressors[0];
            capture.AudioCompressor = filters.AudioCompressors[0];
            capture.FrameRate = NTSC; // NTSC
            capture.FrameSize = new Size(640, 480); // 640x480
            capture.AudioSamplingRate = 44100; // 44.1 kHz
            capture.AudioSampleSize = 16; // 16-bit
            capture.AudioChannels = 2; // Stereo
        }