GithubHelp home page GithubHelp logo

13824125580 / mmalsharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from techyian/mmalsharp

0.0 2.0 0.0 1.99 MB

Unofficial C# API for the Raspberry Pi camera. Supports Mono 4.x and .NET Standard 2.0

License: MIT License

C# 100.00%

mmalsharp's Introduction

MMALSharp - C#/.NET API for the Raspberry Pi camera

Build status

MMALSharp is an unofficial C# API for the Raspberry Pi camera. Under the hood, MMALSharp makes use of the native MMAL interface designed by Broadcom.

MMALSharp supports the following runtimes:

  1. Mono 4.x
  2. .NET Standard 2.0

Installation

MMALSharp NuGet package: NuGet version

PM> Install-Package MMALSharp

Basic Examples

Take a JPEG image using YUV420 encoding:

static void Main(string[] args)
{                        
    MMALCamera cam = MMALCamera.Instance;

    AsyncContext.Run(async () =>
    {                
        using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/", "jpg"))        
        {            
            await cam.TakePicture(imgCaptureHandler, MMALEncoding.JPEG, MMALEncoding.I420);
        }
    });

    cam.Cleanup();
}

Take a H.264 video using YUV420 encoding at 30 fps:

static void Main(string[] args)
{                        
    MMALCamera cam = MMALCamera.Instance;

    AsyncContext.Run(async () =>
    {                
        using (var vidCaptureHandler = new VideoStreamCaptureHandler("/home/pi/videos/", "avi"))        
        {    
            var cts = new CancellationTokenSource(TimeSpan.FromMinutes(3));
            //Take video for 3 minutes.
            await cam.TakeVideo(vidCaptureHandler, cts.Token);
        }
    });

    cam.Cleanup();
}

Documentation

For full installation instructions for Mono 4.x and .NET Core, including configuration and examples - please visit the Wiki site.

Notes & Known issues

When using more resource intensive encoders such as MMAL_ENCODING_BMP and the Sony IMX219 module, I've found it necessary to increase the memory split to around 200mb or otherwise you'll receive an ENOSPC error due to insufficient resources.

Video decoder issue - I've tested a working pipeline as follows:

H264 YUV420 encode -> YUV420 decode -> MJPEG YUV420 encode does work, however the bitrate appears to be extremely low and the resulting video is very pixelated. I'm going to do some more investigating and see whether it's an issue with MMALSharp specifically or the native framework.

License

MIT license

Copyright (c) 2016-2018 Ian Auty

Raspberry Pi is a trademark of the Raspberry Pi Foundation

Special thanks

Dave Jones @waveform80 - your Python header conversions have saved me numerous hours so far. Thank you very much.

Contributors

Daniel Lerch @daniel-lerch

mmalsharp's People

Contributors

techyian avatar daniel-lerch avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.