Exemplo n.º 1
0
        private void StartDecoding()
        {
            try
            {
                IsPlaying = true;

                try
                {
                    _readingTask.Start();
                }
                catch (ThreadStartException)
                {
                }

                try
                {
                    _readingTask.Wait();
                }
                catch (NullReferenceException)
                {
                }
                catch (FFMpegException)
                {
                }
            }
            finally
            {
                IsPlaying = false;
            }
        }
Exemplo n.º 2
0
        private void Init()
        {
            _age       = new FaceAge(AppId, AgeKey);
            _gender    = new FaceGender(AppId, GenderKey);
            _traking   = LocatorFactory.GetTrackingLocator(AppId, FtKey, _age, _gender) as FaceTracking;
            _detection = LocatorFactory.GetDetectionLocator(AppId, FdKey) as FaceDetection;
            _recognize = new FaceRecognize(AppId, FrKey);
            _processor = new FaceProcessor(_traking, _recognize);

            //init cache
            if (Directory.Exists(FaceLibraryPath))
            {
                var files = Directory.GetFiles(FaceLibraryPath);
                foreach (var file in files)
                {
                    var info = new FileInfo(file);
                    _cache.Add(info.Name.Replace(info.Extension, ""), File.ReadAllBytes(file));
                }
            }

            stride     = width * pixelSize;
            bufferSize = stride * height;

            _pImage = Marshal.AllocHGlobal(bufferSize);
            _image  = new Bitmap(width, height, stride, PixelFormat.Format24bppRgb, _pImage);

            var ffmpeg = new FFMpegConverter();

            outputStream = new MemoryStream();

            var setting =
                new ConvertSettings
            {
                CustomOutputArgs = "-s 1920x1080", //根据业务需求-r参数可以调整,取决于摄像机的FPS
            };                                     //-s 1920x1080 -q:v 2 -b:v 64k

            //-an -r 15 -pix_fmt bgr24 -updatefirst 1
            //task = ffmpeg.ConvertLiveMedia("rtsp://*****:*****@192.168.1.64:554/h264/ch1/main/av_stream", null,
            //    outputStream, Format.raw_video, setting);

            /*
             * USB摄像头捕获
             * 通过ffmpeg可以捕获USB摄像,如下代码所示。
             * 首先通过:ffmpeg -list_devices true -f dshow -i dummy命令,可以列出系统中存在的USB摄像设备(或通过控制面板的设备管理工具查看设备名称),例如在我电脑中叫USB2.0 PC CAMERA。
             * 然后根据捕获的分辨率,修改视频图形信息,包括width和height,一般像素大小不用修改,如果要参考设备支持的分辨率,可以使用:
             * ffmpeg -list_options true -f dshow -i video="USB2.0 PC CAMERA"命令
             */
            task = ffmpeg.ConvertLiveMedia("video=Logitech HD Webcam C270", "dshow",
                                           outputStream, Format.raw_video, setting);

            task.OutputDataReceived += DataReceived;
            task.Start();

            _renderTask = new Task(Render);
            _renderTask.Start();
        }
Exemplo n.º 3
0
        private void Init()
        {
            _traking   = LocatorFactory.GetTrackingLocator(AppId, FtKey) as FaceTracking;
            _detection = LocatorFactory.GetDetectionLocator(AppId, FdKey) as FaceDetection;
            _recognize = new FaceRecognize(AppId, FrKey);
            _processor = new FaceProcessor(_traking, _recognize);

            //init cache
            if (Directory.Exists(FaceLibraryPath))
            {
                var files = Directory.GetFiles(FaceLibraryPath);
                foreach (var file in files)
                {
                    var info = new FileInfo(file);
                    _cache.Add(info.Name.Replace(info.Extension, ""), File.ReadAllBytes(file));
                }
            }

            _pImage = Marshal.AllocHGlobal(1920 * 1080 * 3);
            _image  = new Bitmap(1920, 1080, 1920 * 3, PixelFormat.Format24bppRgb, _pImage);

            var ffmpeg = new FFMpegConverter();

            outputStream = new MemoryStream();

            var setting =
                new ConvertSettings
            {
                CustomOutputArgs = "-an -r 15 -pix_fmt bgr24 -updatefirst 1" //根据业务需求-r参数可以调整,取决于摄像机的FPS
            };                                                               //-s 1920x1080 -q:v 2 -b:v 64k

            task = ffmpeg.ConvertLiveMedia("rtsp://*****:*****@192.168.1.64:554/h264/ch1/main/av_stream", null,
                                           outputStream, Format.raw_video, setting);

            task.OutputDataReceived += DataReceived;
            task.Start();

            _renderTask = new Task(Render);
            _renderTask.Start();
        }
Exemplo n.º 4
0
        private void stream_Click(object x, EventArgs y)
        {
            // Get the IDeckLinkOutput interface
            var input  = (IDeckLinkInput)_DeckLink;
            var output = (IDeckLinkOutput)_DeckLink;

            if (_Streaming)
            {
                KillStream();
            }
            else
            {
                IDeckLinkDisplayModeIterator displayIterator;
                input.GetDisplayModeIterator(out displayIterator);

                var supportedModes = new List <IDeckLinkDisplayMode>();

                input.SetCallback(this);
                input.SetScreenPreviewCallback(this);

                var flags   = _BMDVideoInputFlags.bmdVideoInputFlagDefault | _BMDVideoInputFlags.bmdVideoInputEnableFormatDetection;
                var format  = _BMDPixelFormat.bmdFormat8BitYUV;
                var display = _BMDDisplayMode.bmdModeHD1080i50;

                _BMDDisplayModeSupport support;
                IDeckLinkDisplayMode   tmp;
                input.DoesSupportVideoMode(display, format, flags, out support, out tmp);

                if (support != _BMDDisplayModeSupport.bmdDisplayModeSupported)
                {
                    throw new Exception("display mode not working: " + support);
                }

                if (writeRaw.Checked)
                {
                    _VideoWriter = new BinaryWriter(File.Open(_RawVideoFile, FileMode.OpenOrCreate));
                    _AudioWriter = new BinaryWriter(File.Open(_RawAudioFile, FileMode.OpenOrCreate));
                }

                if (writeEncoded.Checked)
                {
                    _EncodedStream = new FileStream(_EncodedVideoFile, FileMode.Create, FileAccess.Write);

                    _EncodeTask = _VideoConverter.ConvertLiveMedia(
                        "rawvideo",
                        _EncodedStream,
                        "h264",
                        new ConvertSettings()
                    {
                        CustomInputArgs = " -pix_fmt uyvy422 -video_size 1920x1080 -framerate 25",
                    });

                    _EncodeTask.Start();
                }

                input.EnableVideoInput(display, format, flags);
                input.EnableAudioInput(_AudioSampleRate, _AudioSampleType, _AudioChannels);

                input.StartStreams();

                stream.Text = "Kill";
                _Streaming  = true;
            }
        }