SebastianGuzmanMorla.LibCamera 1.0.6

dotnet add package SebastianGuzmanMorla.LibCamera --version 1.0.6
NuGet\Install-Package SebastianGuzmanMorla.LibCamera -Version 1.0.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SebastianGuzmanMorla.LibCamera" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SebastianGuzmanMorla.LibCamera --version 1.0.6
#r "nuget: SebastianGuzmanMorla.LibCamera, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SebastianGuzmanMorla.LibCamera as a Cake Addin
#addin nuget:?package=SebastianGuzmanMorla.LibCamera&version=1.0.6

// Install SebastianGuzmanMorla.LibCamera as a Cake Tool
#tool nuget:?package=SebastianGuzmanMorla.LibCamera&version=1.0.6

LibCamera

C# Wrapper to Raspberry Pi libcamera

Example

using LibCamera;
using LibCamera.Settings;
using LibCamera.Settings.Codecs;
using LibCamera.Settings.Encodings;
using LibCamera.Settings.Enumerations;
using LibCamera.Settings.Types;
using System.Diagnostics;
using System.Text.Json;

JsonSerializerOptions JsonSerializerOptions = new()
{
    WriteIndented = true
};

List<Camera>? Cameras = await Hello.ListCameras();

if (Cameras is null)
{
    Console.Error.WriteLine("Failed to list cameras");

    return 1;
}

Console.WriteLine("Found {0} camera(s)", Cameras.Count);

if (Cameras.Count == 0)
{
    return 1;
}

Console.WriteLine("Cameras: {0}", JsonSerializer.Serialize(Cameras, JsonSerializerOptions));

Console.WriteLine("Select camera:");

Camera? Camera = null;

while (true)
{
    string? Input = Console.ReadLine();

    if (Input != null && int.TryParse(Input, out int Id) && Id >= 0 && Cameras.FirstOrDefault(c => c.Id == Id) is Camera SelectedCamera)
    {
        Camera = SelectedCamera;

        break;
    }

    Console.WriteLine("Please enter a valid camera ID");
}

if (Camera is null)
{
    Console.Error.WriteLine("Failed to select camera");

    return 1;
}

StillSettings stillSettings = new Jpg()
{
    Camera = Camera.Id,
    Width = 1280,
    Height = 720,
    Timeout = 0,
    HFlip = true,
    VFlip = true,
    WhiteBalance = WhiteBalance.Incandescent,
    Mode = Camera.Modes.FirstOrDefault(), // Obtained first mode but you can select any mode
    Immediate = true, // Capture immediately instead of waiting for a trigger
    Output = "test.jpg"
};

Console.WriteLine("Start Still using: {0}", JsonSerializer.Serialize(stillSettings, JsonSerializerOptions));

ProcessStartInfo StillStartInfo = Still.CaptureStartInfo(stillSettings);

Process? StillProcess = null;

try
{
    Console.WriteLine("Starting process with command: {0} {1}", StillStartInfo.FileName, StillStartInfo.Arguments);

    StillProcess = Process.Start(StillStartInfo);
}
catch (Exception ex)
{
    Console.Error.WriteLine("Failed to start process: {0}", ex.Message);
}

if (StillProcess is null)
{
    return 1;
}

Console.WriteLine("Started process with ID {0}", StillProcess.Id);

await StillProcess.WaitForExitAsync();

if (StillProcess.ExitCode != 0)
{
    Console.Error.WriteLine("Process exited with code {0}", StillProcess.ExitCode);

    return 1;
}

VideoSettings videoSettings = new H264()
{
    Camera = Camera.Id,
    Width = 1280,
    Height = 720,
    Timeout = 0,
    HFlip = true,
    VFlip = true,
    WhiteBalance = WhiteBalance.Incandescent,
    Mode = Camera.Modes.FirstOrDefault(), // Obtained first mode but you can select any mode
    Output = "test.h264"
};

Console.WriteLine("Start Video using: {0}", JsonSerializer.Serialize(videoSettings, JsonSerializerOptions));

ProcessStartInfo CaptureStartInfo = Video.CaptureStartInfo(videoSettings);

Process? CaptureProcess = null;

try
{
    Console.WriteLine("Starting process with command: {0} {1}", CaptureStartInfo.FileName, CaptureStartInfo.Arguments);

    CaptureProcess = Process.Start(CaptureStartInfo);
}
catch (Exception ex)
{
    Console.Error.WriteLine("Failed to start process: {0}", ex.Message);
}

if (CaptureProcess is null)
{
    return 1;
}

Console.WriteLine("Started process with ID {0}", CaptureProcess.Id);

Console.WriteLine("Press any key to stop recording");

Console.ReadKey();

if (CaptureProcess.HasExited)
{
    Console.Error.WriteLine("Process has already exited");

    return 1;
}

try
{
    CaptureProcess.Kill();
}
catch (Exception ex)
{
    Console.Error.WriteLine("Failed to kill process: {0}", ex.Message);

    return 1;
}

Console.WriteLine("Stopped process with ID {0}", CaptureProcess.Id);

return 0;
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 396 1/17/2024
1.0.5 173 1/11/2024
1.0.4 82 1/11/2024
1.0.3 82 1/11/2024
1.0.2 111 1/10/2024
1.0.1 186 1/4/2024
1.0.0 128 1/1/2024