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

Commit

Permalink
Force raw video to avi format closes #13. Add capture handler to Take…
Browse files Browse the repository at this point in the history
…RawPicture method parameters #19
  • Loading branch information
techyian committed May 4, 2017
1 parent 0e38205 commit 0e7893e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/MMALSharp.FFmpeg/Handlers/FFmpegCaptureHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public static FFmpegCaptureHandler RTMPStreamer(string streamName, string stream
}

/// <summary>
/// Records video from the standard output stream via FFmpeg into a video file that can be opened without explicit command line flags.
/// Records video from the standard output stream via FFmpeg, forcing it into an avi container that can be opened by media players without explicit command line flags.
/// </summary>
/// <param name="directory">The directory to store the output video file</param>
/// <param name="extension">The extension of the video file</param>
/// <param name="filename">The name of the video file</param>
/// <returns></returns>
public static FFmpegCaptureHandler RawVideoToH264(string directory, string extension)
public static FFmpegCaptureHandler RawVideoToAvi(string directory, string filename)
{
System.IO.Directory.CreateDirectory(directory);

return new FFmpegCaptureHandler($"-re -i - -c:v libx264 {directory.TrimEnd()}/out.{extension.TrimStart('.')}");
return new FFmpegCaptureHandler($"-re -i - -c:v copy -an -f avi {directory.TrimEnd()}/{filename}.avi");
}

public FFmpegCaptureHandler(string argument)
Expand Down
17 changes: 12 additions & 5 deletions src/MMALSharp/MMALCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MMALSharp.Handlers;

namespace MMALSharp
{
Expand Down Expand Up @@ -35,8 +36,8 @@ public sealed class MMALCamera

private static readonly Lazy<MMALCamera> lazy = new Lazy<MMALCamera>(() => new MMALCamera());

public static MMALCamera Instance { get { return lazy.Value; } }
public static MMALCamera Instance => lazy.Value;

private MMALCamera()
{
BcmHost.bcm_host_init();
Expand Down Expand Up @@ -130,14 +131,20 @@ public async Task TakeVideo(MMALPortImpl connPort, DateTime? timeout = null, Spl
/// Capture raw image data directly from the Camera component - this method does not use an Image encoder.
/// </summary>
/// <returns>The awaitable Task</returns>
public async Task TakeRawPicture()
public async Task TakeRawPicture(ICaptureHandler handler)
{
var encoder = this.Encoders.Where(c => c.Connection != null && c.Connection.OutputPort == this.Camera.StillPort).FirstOrDefault();

if (encoder != null)
{
throw new PiCameraError("A connection was found to the Camera still port. No encoder should be connected to the Camera's still port for raw capture.");
}
if (handler == null)
{
throw new PiCameraError("No handler specified");
}

this.Camera.Handler = handler;

this.CheckPreviewComponentStatus();

Expand All @@ -151,6 +158,7 @@ public async Task TakeRawPicture()
finally
{
this.Camera.Handler.PostProcess();
this.Camera.Handler.Dispose();
}
}

Expand All @@ -166,8 +174,7 @@ public async Task TakePicture(MMALPortImpl connPort, bool rawBayer = false, bool
{
if (connPort == null)
{
await TakeRawPicture();
return;
throw new PiCameraError("The port an Image encoder is attached to has not been specified.");
}

//Find the encoder/decoder which is connected to the output port specified.
Expand Down

0 comments on commit 0e7893e

Please sign in to comment.