Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
#99. Add raw video helper method.
Browse files Browse the repository at this point in the history
  • Loading branch information
techyian committed Jan 17, 2020
1 parent 2950df8 commit 98c0fc6
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/MMALSharp/MMALCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,46 @@ public void ForceStop(IOutputPort port)
});
}

/// <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(IOutputCaptureHandler handler, CancellationToken cancellationToken, Split split = null)
public async Task TakeVideo(IVideoCaptureHandler handler, CancellationToken cancellationToken, Split split = null)
{
if (split != null && !MMALCameraConfig.InlineHeaders)
{
Expand Down Expand Up @@ -116,7 +148,7 @@ public async Task TakeVideo(IOutputCaptureHandler handler, CancellationToken can
await this.ProcessAsync(this.Camera.VideoPort, cancellationToken).ConfigureAwait(false);
}
}

/// <summary>
/// Self-contained method to capture raw image data directly from the Camera component - this method does not use an Image encoder.
/// Note: We cannot use the OPAQUE encoding format with this helper method, the capture will not fail, but will not produce valid data. For reference, RaspiStillYUV uses YUV420.
Expand Down

0 comments on commit 98c0fc6

Please sign in to comment.