示例#1
0
        public CameraEncoder(VideoEncodeCfg cfgVideo, Action <MediaFrame> callBack, Canvas canvas = null)
        {
            _cfgVideo   = cfgVideo;
            _fps        = cfgVideo.FrameRate;
            this.Canvas = canvas;
            _capturer   = CreateCapturer();
            var @params = new X264Params(_cfgVideo.Width, _cfgVideo.Height, _fps, cfgVideo.VideoBitRate);

            if (cfgVideo.Params.ContainsKey("X264Encode"))
            {
                @params.method = (int)cfgVideo.Params["X264Encode"];
            }

            if (cfgVideo.Params.ContainsKey("KeyFrameRate"))
            {
                @params.key_frame_max = (int)cfgVideo.Params["KeyFrameRate"];
            }


            _x264 = new X264Native(@params);
            _x264.Init();
            _ffscale = new FFScale(_cfgVideo.Width, _cfgVideo.Height, 0, 12, _cfgVideo.Width, _cfgVideo.Height, 12, 12);
            _draw    = cfgVideo.Draw;
            _draw.SetSize(_cfgVideo.Width, _cfgVideo.Height);
            _callBack = callBack;
        }
示例#2
0
        private void Init(MediaFrame frame, bool reinit = false)
        {
            if (_inited && !reinit)
            {
                return;
            }

            if (_ffimp != null)
            {
                _ffimp.Release();
            }

            _inited = true;
            _width  = frame.nWidth;
            _height = frame.nHeight;
            _ffimp  = new FFImp(AVCodecCfg.CreateVideo(_width, _height), true, true);
            if (_yuvDraw == null && _control != null)
            {
                _yuvDraw = new YUVGDIDraw(_control);
            }
            _yuvDraw.SetSize(_width, _height);

            _yuvDataBuffer = new byte[_width * _height * 3 / 2];

            _drawHandle = new Action <byte[]>(Draw);
        }