/// <summary> /// Self-contained method for recording raw video frames directly from the camera's video port. /// Uses the encoding and pixel format as set in <see cref="MMALCameraConfig.VideoEncoding"/> and <see cref="MMALCameraConfig.VideoSubformat"/>. /// </summary> /// <param name="handler">The video capture handler to apply to the encoder.</param> /// <param name="cancellationToken">A cancellationToken to signal when to stop video capture.</param> /// <returns>The awaitable Task.</returns> public async Task TakeRawVideo(IVideoCaptureHandler handler, CancellationToken cancellationToken) { using (var splitter = new MMALSplitterComponent()) using (var renderer = new MMALVideoRenderer()) { this.ConfigureCameraSettings(); var splitterOutputConfig = new MMALPortConfig(MMALCameraConfig.VideoEncoding, MMALCameraConfig.VideoSubformat, 0); // Force port type to SplitterVideoPort to prevent resolution from being set against splitter component. splitter.ConfigureOutputPort <SplitterVideoPort>(0, splitterOutputConfig, handler); // Create our component pipeline. this.Camera.VideoPort.ConnectTo(splitter); this.Camera.PreviewPort.ConnectTo(renderer); MMALLog.Logger.LogInformation($"Preparing to take raw video. Resolution: {this.Camera.VideoPort.Resolution.Width} x {this.Camera.VideoPort.Resolution.Height}. " + $"Encoder: {MMALCameraConfig.VideoEncoding.EncodingName}. Pixel Format: {MMALCameraConfig.VideoSubformat.EncodingName}."); // Camera warm up time await Task.Delay(2000).ConfigureAwait(false); await this.ProcessAsync(this.Camera.VideoPort, cancellationToken).ConfigureAwait(false); } }
/// <summary> /// Self-contained method for recording H.264 video for a specified amount of time. Records at 30fps, 25Mb/s at the highest quality. /// </summary> /// <param name="handler">The video capture handler to apply to the encoder.</param> /// <param name="cancellationToken">A cancellationToken to signal when to stop video capture.</param> /// <param name="split">Used for Segmented video mode.</param> /// <returns>The awaitable Task.</returns> public async Task TakeVideo(IVideoCaptureHandler handler, CancellationToken cancellationToken, Split split = null) { if (split != null && !MMALCameraConfig.InlineHeaders) { MMALLog.Logger.LogWarning("Inline headers not enabled. Split mode not supported when this is disabled."); split = null; } using (var vidEncoder = new MMALVideoEncoder()) using (var renderer = new MMALVideoRenderer()) { this.ConfigureCameraSettings(); var portConfig = new MMALPortConfig(MMALEncoding.H264, MMALEncoding.I420, 10, MMALVideoEncoder.MaxBitrateLevel4, null, split); vidEncoder.ConfigureOutputPort(portConfig, handler); // Create our component pipeline. this.Camera.VideoPort.ConnectTo(vidEncoder); this.Camera.PreviewPort.ConnectTo(renderer); MMALLog.Logger.LogInformation($"Preparing to take video. Resolution: {this.Camera.VideoPort.Resolution.Width} x {this.Camera.VideoPort.Resolution.Height}. " + $"Encoder: {vidEncoder.Outputs[0].EncodingType.EncodingName}. Pixel Format: {vidEncoder.Outputs[0].PixelFormat.EncodingName}."); // Camera warm up time await Task.Delay(2000).ConfigureAwait(false); await this.ProcessAsync(this.Camera.VideoPort, cancellationToken).ConfigureAwait(false); } }