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

Commit

Permalink
Adding bitrate value in MMALVideoEncoder, resolves #67. Fixing TakePi…
Browse files Browse the repository at this point in the history
…ctureTimeout and TakePictureTimelapse so they don't rely on TakePicture as Task.Delay was being called each run.
  • Loading branch information
techyian committed Jul 18, 2018
1 parent f933082 commit 284ee0d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ internal void ConfigureBitrate(int outputPort)
this.Bitrate = MaxBitrateMJPEG;
}
}

this.Outputs[outputPort].Ptr->Format->Bitrate = this.Bitrate;
this.Outputs[outputPort].Ptr->Format->Es->Video.FrameRate = new MMAL_RATIONAL_T(0, 1);
this.Outputs[outputPort].Commit();
}

internal void ConfigureRateControl(int outputPort)
Expand Down
65 changes: 49 additions & 16 deletions src/MMALSharp/MMALCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,24 @@ public async Task TakePictureTimeout(ImageStreamCaptureHandler handler, MMALEnco
this.Camera.StillPort.SetParameter(MMALParametersCamera.MMAL_PARAMETER_CAMERA_BURST_CAPTURE, true);
}

while (!cancellationToken.IsCancellationRequested)
using (var imgEncoder = new MMALImageEncoder(handler))
using (var renderer = new MMALNullSinkComponent())
{
await this.TakePicture(handler, encodingType, pixelFormat);
this.ConfigureCameraSettings();

imgEncoder.ConfigureOutputPort(encodingType, pixelFormat, 90);

// Create our component pipeline.
this.Camera.StillPort.ConnectTo(imgEncoder);
this.Camera.PreviewPort.ConnectTo(renderer);

// Camera warm up time
await Task.Delay(2000);

while (!cancellationToken.IsCancellationRequested)
{
await this.ProcessAsync(this.Camera.StillPort);
}
}
}

Expand All @@ -251,24 +266,42 @@ public async Task TakePictureTimelapse(ImageStreamCaptureHandler handler, MMALEn
throw new ArgumentNullException(nameof(timelapse), "Timelapse object null. This must be initialized for Timelapse mode");
}

while (!timelapse.CancellationToken.IsCancellationRequested)
using (var imgEncoder = new MMALImageEncoder(handler))
using (var renderer = new MMALNullSinkComponent())
{
switch (timelapse.Mode)
this.ConfigureCameraSettings();

imgEncoder.ConfigureOutputPort(encodingType, pixelFormat, 90);

// Create our component pipeline.
this.Camera.StillPort.ConnectTo(imgEncoder);
this.Camera.PreviewPort.ConnectTo(renderer);

// Camera warm up time
await Task.Delay(2000);

while (!timelapse.CancellationToken.IsCancellationRequested)
{
case TimelapseMode.Millisecond:
interval = timelapse.Value;
break;
case TimelapseMode.Second:
interval = timelapse.Value * 1000;
break;
case TimelapseMode.Minute:
interval = (timelapse.Value * 60) * 1000;
break;
}
switch (timelapse.Mode)
{
case TimelapseMode.Millisecond:
interval = timelapse.Value;
break;
case TimelapseMode.Second:
interval = timelapse.Value * 1000;
break;
case TimelapseMode.Minute:
interval = (timelapse.Value * 60) * 1000;
break;
}

await Task.Delay(interval);
await Task.Delay(interval);

await this.TakePicture(handler, encodingType, pixelFormat);
MMALLog.Logger.Info($"Preparing to take picture. Resolution: {imgEncoder.Width} x {imgEncoder.Height}. " +
$"Encoder: {encodingType.EncodingName}. Pixel Format: {pixelFormat.EncodingName}.");

await this.ProcessAsync(this.Camera.StillPort);
}
}
}

Expand Down

0 comments on commit 284ee0d

Please sign in to comment.