pappersverk / rpi_fb_capture

Capture the Raspberry Pi's framebuffer
Apache License 2.0
11 stars 2 forks source link

RpiFbCapture

CircleCI Hex version

This library can capture the Raspberry Pi's framebuffer. This lets you do things like:

The capture occurs in a separate port process which can be supervised like other Elixir processes.

The native Raspberry Pi framebuffer is captured in 16-bit RGB. That raw buffer can be reported or any of these formats:

Device Support

RpiFbCapture supports all Raspberry PI's except the RPI4 and RPI4000 (more discussion in https://github.com/pappersverk/rpi_fb_capture/issues/8)

Installation

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

def deps do
  [
    {:rpi_fb_capture, "~> 0.1.0"}
  ]
end

Example use

To try it out, you'll need a Raspberry Pi. It doesn't need to be attached to a display.

# Specify width and height if you're only interested in part of the display.
# Specify 0's or leave missing to capture everything.
iex> {:ok, cap} = RpiFbCapture.start_link(width: 0, height: 0)
{:ok, #PID<0.4794.0>}

# Perform the capture - choose ppm since it's easy to view
iex> {:ok, frame} = RpiFbCapture.capture(cap, :ppm)
{:ok,
 %RpiFbCapture.Capture{
   data: [
     "P6 720 480 255\n",
     <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>
   ],
   format: :ppm,
   height: 480,
   width: 720
 }}

# Save the capture to a file
iex> File.write("capture.ppm", frame.data)
:ok

Normally you'll be sending the captured data somewhere or processing it. If you do find that you're just taking one-off screenshots, take a look at RpiFbCapture.save/2 to save some typing.

If you're using Nerves, use sftp to copy the file off the device and view or if on Raspbian, view it locally.