public override IDownstreamComponent ConfigureOutputPort(int outputPort, IMmalPortConfig config, ICaptureHandler handler) { var bufferSize = Math.Max(Outputs[outputPort].Ptr->BufferSizeRecommended, Outputs[outputPort].Ptr->BufferSizeMin); var bitrate = GetValidBitrate(config); // Force framerate to be 0 in case it was provided by user. config = new MmalPortConfig( config.EncodingType, config.PixelFormat, config.Quality, bitrate, config.Timeout, config.Split, config.StoreMotionVectors, config.Width, config.Height, config.Framerate, config.ZeroCopy, config.BufferNum, bufferSize, config.Crop); base.ConfigureOutputPort(outputPort, config, handler); ConfigureIntraPeriod(outputPort); ConfigureVideoProfile(outputPort); ConfigureInlineHeaderFlag(outputPort); ConfigureInlineVectorsFlag(outputPort); ConfigureIntraRefresh(outputPort); ConfigureQuantisationParameter(outputPort, config.Quality); ConfigureImmutableInput(); return(this); }
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); }
void InitialiseStill() { var currentWidth = CameraConfig.Resolution.Width; var currentHeight = CameraConfig.Resolution.Height; if (currentWidth == 0 || currentWidth > CameraInfo.MaxWidth) { currentWidth = CameraInfo.MaxWidth; } if (currentHeight == 0 || currentHeight > CameraInfo.MaxHeight) { currentHeight = CameraInfo.MaxHeight; } CameraConfig.Resolution = new Resolution(currentWidth, currentHeight); var resolution = CameraConfig.Resolution.Pad(); var portConfig = new MmalPortConfig( CameraConfig.Encoding, CameraConfig.EncodingSubFormat, width: resolution.Width, height: resolution.Height, framerate: CameraConfig.Framerate, bufferNum: Math.Max(StillPort.BufferNumRecommended, 3), bufferSize: Math.Max(StillPort.BufferSizeRecommended, StillPort.BufferSizeMin), crop: new Rectangle(0, 0, currentWidth, currentHeight)); MmalLog.Logger.LogDebug("Commit still"); StillPort.Configure(portConfig, null, null); // Use Raspistill values. if (CameraConfig.ShutterSpeed > 6000000) { StillPort.SetFramerateRange(new MmalRational(5, 1000), new MmalRational(166, 1000)); } else if (CameraConfig.ShutterSpeed > 1000000) { StillPort.SetFramerateRange(new MmalRational(167, 1000), new MmalRational(999, 1000)); } }
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); }
void InitialisePreview() { var portConfig = new MmalPortConfig( CameraConfig.Encoding, CameraConfig.EncodingSubFormat, width: CameraConfig.Resolution.Width, height: CameraConfig.Resolution.Height, framerate: CameraConfig.Framerate); MmalLog.Logger.LogDebug("Commit preview"); PreviewPort.Configure(portConfig, null, null); // Use Raspistill values. if (CameraConfig.ShutterSpeed > 6000000) { PreviewPort.SetFramerateRange(new MmalRational(5, 1000), new MmalRational(166, 1000)); } else if (CameraConfig.ShutterSpeed > 1000000) { PreviewPort.SetFramerateRange(new MmalRational(166, 1000), new MmalRational(999, 1000)); } }
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); }