public async Task Capture(Action <byte[]> onVideoDataAvailable, CancellationToken cancellationToken, int videoQuantisation = 0, int videoBitrate = 2386093) { _camera.Initialise(); var videoCaptureHandler = new InMemoryVideoHandler(); var vidEncoder = new MmalVideoEncoder(); var nullSink = new MmalNullSinkComponent(); videoCaptureHandler.SetOnVideoDataAvailable(data => onVideoDataAvailable?.Invoke(data)); _cameraDisposables.AddRange(new IDisposable[] { videoCaptureHandler, vidEncoder, nullSink }); var videoPortConfig = new MmalPortConfig( MmalEncoding.H264, MmalEncoding.I420, videoQuantisation, videoBitrate, null, null, false, CameraConfig.Resolution.Width, CameraConfig.Resolution.Height); vidEncoder.ConfigureOutputPort(videoPortConfig, videoCaptureHandler); _camera.VideoPort.ConnectTo(vidEncoder); _camera.PreviewPort.ConnectTo(nullSink); // Camera warm up time await Task.Delay(MmalCameraWarmUpMs, cancellationToken); await ProcessAsync(_camera.VideoPort, cancellationToken); }
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); }