Exemple #1
0
        public async Task Capture(Action <byte[]> onVideoDataAvailable, Action <Stream> onFullFrameAvailable, CancellationToken cancellationToken, int videoQuantisation = 0, int videoBitrate = 2386093, int jpegQuality = 80)
        {
            _camera.Initialise();

            var imageCaptureHandler = new InMemoryImageHandler();
            var videoCaptureHandler = new InMemoryVideoHandler();
            var imgEncoder          = new MmalImageEncoder();
            var vidEncoder          = new MmalVideoEncoder();
            var splitter            = new MmalSplitterComponent();
            var nullSink            = new MmalNullSinkComponent();

            videoCaptureHandler.SetOnVideoDataAvailable(data => onVideoDataAvailable?.Invoke(data));
            imageCaptureHandler.SetOnFullFrameAvailable(stream => onFullFrameAvailable?.Invoke(stream));

            _cameraDisposables.AddRange(new IDisposable[] { imageCaptureHandler, videoCaptureHandler, imgEncoder, vidEncoder, splitter, nullSink });

            var imagePortConfig = new MmalPortConfig(MmalEncoding.Jpeg, MmalEncoding.I420, jpegQuality);

            var videoPortConfig = new MmalPortConfig(
                MmalEncoding.H264,
                MmalEncoding.I420,
                videoQuantisation,
                videoBitrate,
                null,
                null,
                false,
                CameraConfig.Resolution.Width,
                CameraConfig.Resolution.Height);

            imgEncoder.ConfigureOutputPort(imagePortConfig, imageCaptureHandler);
            vidEncoder.ConfigureOutputPort(videoPortConfig, videoCaptureHandler);

            _camera.VideoPort.ConnectTo(splitter);
            splitter.Outputs[0].ConnectTo(imgEncoder);
            splitter.Outputs[1].ConnectTo(vidEncoder);
            _camera.PreviewPort.ConnectTo(nullSink);

            // Camera warm up time
            await Task.Delay(MmalCameraWarmUpMs, cancellationToken);

            await ProcessAsync(_camera.VideoPort, cancellationToken);
        }
Exemple #2
0
        public async Task Capture(Action <Stream> onFullFrameAvailable, CancellationToken cancellationToken, int jpegQuality = 80)
        {
            _camera.Initialise();

            var imageCaptureHandler = new InMemoryImageHandler();
            var imgEncoder          = new MmalImageEncoder();
            var nullSink            = new MmalNullSinkComponent();

            imageCaptureHandler.SetOnFullFrameAvailable(stream => onFullFrameAvailable?.Invoke(stream));

            _cameraDisposables.AddRange(new IDisposable[] { imageCaptureHandler, imgEncoder, nullSink });

            var imagePortConfig = new MmalPortConfig(MmalEncoding.Jpeg, MmalEncoding.I420, jpegQuality);

            imgEncoder.ConfigureOutputPort(imagePortConfig, imageCaptureHandler);

            _camera.VideoPort.ConnectTo(imgEncoder);
            _camera.PreviewPort.ConnectTo(nullSink);

            // Camera warm up time
            await Task.Delay(MmalCameraWarmUpMs, cancellationToken);

            await ProcessAsync(_camera.VideoPort, cancellationToken);
        }