示例#1
0
        //----------------<
        //STATIC
        public static ArrayList GetVideoDevices()
        {
            ArrayList videoDevs;

            DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out videoDevs);
            return(videoDevs);
        }
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        public static ArrayList GetAudioDevices()
        {
            ArrayList audioDevs;

            DsDev.GetDevicesOfCat(FilterCategory.AudioInputDevice, out audioDevs);
            return(audioDevs);
        }
示例#5
0
        /// <summary> create the used COM components and get the interfaces. </summary>
        bool GetInterfaces()
        {
            Type   comType = null;
            object comObj  = null;

            try
            {
                graphBuilder = (IGraphBuilder)DsDev.CreateFromCLSID(Clsid.FilterGraph);
                mediaEvt     = (IMediaEvent)graphBuilder;
                AssignTaskToWaitForCompletion(mediaEvt);

                Guid clsid = Clsid.CaptureGraphBuilder2;
                Guid riid  = typeof(ICaptureGraphBuilder2).GUID;
                capGraph = (ICaptureGraphBuilder2)DsBugWO.CreateDsInstance(ref clsid, ref riid);

                if (atiTVCardFound)
                {
                    wmVideoDecoder = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.AVI_Decompressor);
                }

                stretchVideo   = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.Stretch_Video);
                colorConverter = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.ColorSpaceConverter);
                modFrameRate   = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.ModifyFrameRate);

                motionVector = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.MotionVector);
                // Vector Grabber
                vectorGrabber = (IVectorGrabber)DsDev.CreateFromCLSID(Clsid.FlowVectorGrabber);

                sampleGrabber = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.SampleGrabber);
                grabberConfig = sampleGrabber as ISampleGrabber;

                mediaCtrl = (IMediaControl)graphBuilder;

                if (videoPreview)
                {
                    teeSplitter   = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.SmartTee);      //.CreateFromMoniker(TeeSplitter);
                    videoRenderer = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.VideoRenderer); // (Clsid.VMR9);
                }

                // Attemp to use VMR9 abandoned for now
                //vmrAllocator = (IVMRSurfaceAllocator9)DsDev.CreateFromCLSID(Clsid.VMR9Allocator);
                baseGrabFlt = (IBaseFilter)vectorGrabber;
                return(true);
            }
            catch (Exception ee)
            {
                LogInfo(LogGroups.Console, "Could not get interfaces\r\n" + ee.Message);
                return(false);
            }
            finally
            {
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                }
                comObj = null;
            }
        }
示例#6
0
        /// <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;
            }
        }
示例#7
0
        /// <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 -";
        }
示例#8
0
        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);
        }
示例#9
0
        /// <summary>
        /// 获取当前用户可用的所有音频设备
        /// </summary>
        /// <returns></returns>
        public static DsDevice[] GetAllAudioDevice()
        {
            ArrayList arrayList = new ArrayList();

            DsDev.GetDevicesOfCat(FilterCategory.AudioInputDevice, out arrayList);
            DsDevice[] dsArray = new DsDevice[arrayList.Count];
            for (int i = 0; i < arrayList.Count; i++)
            {
                dsArray[i] = arrayList[i] as DsDevice;
            }
            return(dsArray);
        }
示例#10
0
 public void getDevices()
 {
     DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices);
     // устройств несколько необходимо предусмотреть укзанаие с какого устройства выполнять распознаваниае
     if (capDevices.Count >= 0)
     {
         ListViewItem item = null;
         foreach (DsDevice dev in capDevices)
         {
             item           = new ListViewItem(dev.Name);
             item.Tag       = dev;
             SelectedDevice = item.Tag as DsDevice;
         }
     }
 }
示例#11
0
        /// <summary>
        /// 获取当前用户可用的所有摄像头数组
        /// </summary>
        /// <returns>返回当前用户可用的摄像头数组,若没有找到摄像头,则会抛出异常</returns>
        public static DsDevice[] GetAllVideoDevice()
        {
            ArrayList capDevices = new ArrayList();

            DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices); //读摄像头信息
            if (capDevices == null || capDevices.Count == 0)                        //如果摄像头不存在则抛出异常
            {
                //throw new Exception("未找到摄像头设备!");
                return(new DsDevice[0]);
            }
            DsDevice[] dsArray = new DsDevice[capDevices.Count];
            for (int i = 0; i < capDevices.Count; i++)
            {
                dsArray[i] = capDevices[i] as DsDevice;
            }
            return(dsArray);
        }
        /// <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();
            }
        }
示例#13
0
        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)));
        }
        // SaveFileDialog sd;



        public void getDevices()
        {
            DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices);

            if (capDevices.Count >= 1)
            {
                ListViewItem item = null;
                foreach (DsDevice dev in capDevices)
                {
                    item     = new ListViewItem(dev.Name);
                    item.Tag = dev;
                    lvDev.Items.Add(item);
                }
            }

            if (capDevices.Count == 1)
            {
                ListViewItem selItem = lvDev.Items[0];
                SelectedDevice = selItem.Tag as DsDevice;
            }
        }
示例#15
0
        private string GetParams(bool is_push)
        {
            var builder  = new StringBuilder();
            int showflag = 0;

            if (_sourceType == TargetType.File)
            {
                builder.AppendFormat(" -re -i \"{0}\"", _source);
            }

            if (_sourceType == TargetType.Live)
            {
                builder.Append(" -i");
                builder.AppendFormat(
                    -1 < _source.IndexOf("live=1", StringComparison.OrdinalIgnoreCase) ? " \"{0}\" live=1" : " \"{0}\"",
                    _source);
            }

            if (_sourceType == TargetType.Directshow)
            {
                //如果输入是设备开始获取设备名称
                if (DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices, out _dsshow))
                {
                    //获取正常
                    _dsshowname = "\"" + _dsshow + "\"";

                    _dest = " -f dshow -i video=" + _dsshowname + " -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f flv " + _dest + "";
                    builder.Append(_dest);
                }
                else
                {
                    Console.WriteLine("No video capture devices found!");
                    showflag = 1;
                    builder.Clear();
                }
            }

            if (_sourceType != TargetType.Directshow)
            {
                if (_sourceType == TargetType.File)
                {
                    if (_filters.Any(x => x.Name.Equals("Segment", StringComparison.OrdinalIgnoreCase)))
                    {
                        var filter = _filters.First(x => x.Name.Equals("Segment", StringComparison.OrdinalIgnoreCase));
                        _filters.Remove(filter);
                    }
                }


                if (!_filters.Any(x => x.Name.Equals("x264", StringComparison.OrdinalIgnoreCase)))
                {
                    //builder.Append(" -vcodec copy");
                }
                builder.Append(" -acodec copy");
                if (_destType == TargetType.Live)
                {
                    if (!_filters.Any(x => x.Name.Equals("AudioRate", StringComparison.OrdinalIgnoreCase)))
                    {
                        //_filters.Add(new AudioRatelFilter(44100));
                    }

                    if (!_filters.Any(x => x.Name.Equals("AudioBitrate", StringComparison.OrdinalIgnoreCase)))
                    {
                        //_filters.Add(new AudioBitrateFilter(320));
                    }
                }


                if (_sourceType != TargetType.Directshow)
                {
                    var sourcefile = new MediaStream(_source, is_push);
                    foreach (var filter in _filters.OrderBy(x => x.Rank))
                    {
                        filter.Source = sourcefile;
                        builder.Append(filter.Execute());
                    }
                }

                if (_destType == TargetType.File)
                {
                    var dir = Path.GetDirectoryName(_dest);

                    if (string.IsNullOrWhiteSpace(dir))
                    {
                        throw new ApplicationException("output directory error.");
                    }

                    var fileName = Path.GetFileNameWithoutExtension(_dest);

                    if (string.IsNullOrWhiteSpace(fileName))
                    {
                        throw new ApplicationException("output filename is null");
                    }

                    var code = GuessCode(_dest);

                    if (!_filters.Any(x => x.Name.Equals("Segment", StringComparison.OrdinalIgnoreCase)))
                    {
                        // out%d.mp4
                        builder.AppendFormat(" {0}{1}%d{2}", dir, fileName, code.Extension);
                    }
                }

                if (_destType == TargetType.Live)
                {
                    builder.AppendFormat(" -f flv \"{0}\"", _dest);
                }
            }
            return(builder.ToString());
        }
示例#16
0
        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 + "..........";
        }
示例#17
0
        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;
        }
示例#18
0
        /// <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);
            }
        }
示例#19
0
 public ArrayList GetDeviceList()
 {
     DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices);
     return(capDevices);
 }