/// <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); } }
/// <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="timeout">A timeout to stop the video capture</param> /// <param name="split">Used for Segmented video mode</param> /// <returns>The awaitable Task</returns> public async Task TakeVideo(VideoStreamCaptureHandler handler, DateTime?timeout = null, Split split = null) { if (split != null && !MMALCameraConfig.InlineHeaders) { MMALLog.Logger.Warn("Inline headers not enabled. Split mode not supported when this is disabled."); split = null; } using (var vidEncoder = new MMALVideoEncoder(handler, new MMAL_RATIONAL_T(30, 1), timeout, split)) using (var renderer = new MMALVideoRenderer()) { vidEncoder.ConfigureOutputPort(0, MMALEncoding.H264, MMALEncoding.I420, 10, 25000000); //Create our component pipeline. this.Camera.VideoPort.ConnectTo(vidEncoder); this.Camera.PreviewPort.ConnectTo(renderer); this.ConfigureCameraSettings(); MMALLog.Logger.Info($"Preparing to take video. Resolution: {vidEncoder.Width} x {vidEncoder.Height}. " + $"Encoder: {vidEncoder.Outputs[0].EncodingType.EncodingName}. Pixel Format: {vidEncoder.Outputs[0].PixelFormat.EncodingName}."); await BeginProcessing(this.Camera.VideoPort, vidEncoder); } }