/membrane_rpicam_plugin

Membrane rpicam plugin

Primary LanguageElixirApache License 2.0Apache-2.0

Membrane Rpicam Plugin

Hex.pm API Docs CircleCI

Membrane Rpicam Plugin allows capturing video from official RaspberryPi camera module using rpicam-apps (formerly libcamera-apps). This plugin can also be used on devices running Nerves.

Installation

The package can be installed by adding membrane_rpicam_plugin to your list of dependencies in mix.exs:

def deps do
  [
    {:membrane_rpicam_plugin, "~> 0.1.4"}
  ]
end

The package depends on rpicam-apps that need to be present on the target system.

Usage

The following script creates and starts a pipeline capturing 5 seconds from the RaspberryPi camera module and saving it to /data/output.h264:

defmodule Rpicam.Pipeline do
  use Membrane.Pipeline
  
  @impl true
  def handle_init(_ctx, _opts) do
    spec =   
      child(:source, %Membrane.Rpicam.Source{timeout: 5000})
      |> child(:sink, %Membrane.File.Sink{location: "/data/output.h264"})

    {[spec: spec], %{}}
  end

  @impl true
  def handle_element_end_of_stream(:sink, _pad, _ctx, state) do
    {[terminate: :normal], state}
  end

  @impl true
  def handle_element_end_of_stream(_child, _pad, _ctx, state) do
    {[], state}
  end
end

# Start and monitor the pipeline
{:ok, _supervisor_pid, pipeline_pid} = Membrane.Pipeline.start_link(Rpicam.Pipeline)
ref = Process.monitor(pipeline_pid)

# Wait for the pipeline to finish
receive do
  {:DOWN, ^ref, :process, _pipeline_pid, _reason} ->
    :ok
end

Copyright and License

Copyright 2022, Software Mansion

Software Mansion

Licensed under the Apache License, Version 2.0