Exemple #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;
        }
Exemple #2
0
 public ScreenCapturer(int width, int height, int fps, Action <byte[]> callBack)
 {
     _width    = width;
     _height   = height;
     _fps      = fps;
     _callBack = callBack;
     _ffscale  = new FFScale(width, height, 3, 24, width, height, 0, 12);
 }
Exemple #3
0
 public MixerVideoCapturer(Mixer.Video.Canvas canvas, int width, int height, int fps, Action <byte[]> callBack)
 {
     _width      = width;
     _height     = height;
     _fps        = fps;
     _callBack   = callBack;
     this.Canvas = canvas;
     _ffscale    = new FFScale(width, height, 3, 24, width, height, 0, 12);
 }
Exemple #4
0
 public static void Test()
 {
     try {
         FFScale s    = new FFScale(320, 240, 29, 32, 320, 240, 0, 12);
         byte[]  @in  = new byte[320 * 240 * 4];
         byte[]  @out = s.FormatS(@in);
         @out = s.FormatS(@in);
     } catch (Exception e) {
     }
 }
Exemple #5
0
 public void SetSize(int width, int height)
 {
     _width  = width;
     _height = height;
     _scale  = new FFScale(width, height, 0, 12, width, height, 3, 24);
     if (_image != null)
     {
         _image.Dispose();
     }
     _image = null;
     lock (_sync) {
         _buffer = null;
     }
 }
Exemple #6
0
 private void FFScaleSetup(AMMediaType mt)
 {
     //e436eb7d-524f-11ce-9f53-0020af0ba770  RGB24
     //32595559-0000-0010-8000-00aa00389b71  YUY2
     //
     if (mt.subType.ToString() == "32595559-0000-0010-8000-00aa00389b71")
     {
         _ffscale = new FFScale(_width, _height, 1, 12, _width, _height, 0, 12);
     }
     else if (mt.subType.ToString() == "e436eb7d-524f-11ce-9f53-0020af0ba770")
     {
         _ffscale = new FFScale(_width, _height, 2, 24, _width, _height, 0, 12);
     }
     else
     {
         throw new Exception("FFScaleSetup Error");
     }
 }
Exemple #7
0
        public CameraAForge(int camera, int width, int height, Action <byte[]> callBack)
        {
            _callBack    = callBack;
            _ffscale     = new FFScale(width, height, 3, 24, width, height, 0, 12);
            videoDevices = new AForge.Video.DirectShow.FilterInfoCollection(FilterCategory.VideoInputDevice);
            videoDevice  = new AForge.Video.DirectShow.VideoCaptureDevice(videoDevices[camera].MonikerString);
            foreach (var item in videoDevice.VideoCapabilities)
            {
                if (item.FrameSize.Width == width && item.FrameSize.Height == height)
                {
                    videoDevice.VideoResolution = item;
                }
            }
            if (videoDevice.VideoResolution == null)
            {
                throw new Exception(string.Format("摄像头不支持{0}*{1}分辨率", width, height));
            }

            videoDevice.NewFrame    += NewFrame;
            videoDevice.RGBRawFrame += YUVFrame;
        }
Exemple #8
0
        public FFImp(AVCodecCfg cfg, bool isDec, bool isvideo = true)
        {
            this.isDec = isDec;
            this.cfg   = cfg;
            var pcfg = FunctionEx.StructToIntPtr(cfg);

            pAVObj = FunctionEx.StructToIntPtr(new AVModel());
            lock (_lock) {
                if (!ffimp_init())
                {
                    throw new Exception("ffimp init error");
                }
            }
            if (isvideo)
            {
                int pOutBufSize = cfg.width * cfg.height * 3;
                if (pOutBufSize == 0)
                {
                    pOutBufSize = 1920 * 1080 * 4;
                }
                pOutBuf = Marshal.AllocHGlobal(pOutBufSize);
                int init_r = 0;
                lock (_lock)
                {
                    if (this.isDec)
                    {
                        init_r = ffimp_video_decode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize);
                    }
                    else
                    {
                        init_r = ffimp_video_encode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize);
                    }

                    _ffscale = new FFScale(cfg.width, cfg.height, 0, 12, cfg.width, cfg.height, 0, 12);
                }
            }
            else
            {
                int pOutBufSize = cfg.width * cfg.height * 3;
                if (pOutBufSize == 0)
                {
                    pOutBufSize = 2048 * 2;
                }
                pOutBuf = Marshal.AllocHGlobal(pOutBufSize);
                int init_r = 0;
                lock (_lock)
                {
                    if (this.isDec)
                    {
                        init_r = ffimp_audio_decode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize);
                    }
                    else
                    {
                        init_r = ffimp_audio_decode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize);
                    }

                    //  _ffscale = new FFScale(cfg.width, cfg.height, 0, 12, cfg.width, cfg.height, 0, 12);
                }
            }
            Marshal.FreeHGlobal(pcfg);
        }