BB.Camera.AVF.Devices (bb_camera_avf v0.1.0)

Copy Markdown View Source

The video devices ffmpeg's AVFoundation input can see.

This asks ffmpeg rather than AVFoundation, because ffmpeg is what will open the camera: a name is only useful as a :device option if it is the name ffmpeg matches against, spelled the way ffmpeg spells it.

ffmpeg lists screens alongside cameras, after them, as Capture screen N. They are video devices ffmpeg can open, so they are reported, but marked as screens rather than cameras.

Listing does not open any device, and needs no camera access.

Summary

Functions

Ask ffmpeg for its video devices.

Read the video devices out of ffmpeg's -list_devices output.

Types

device()

@type device() :: %{index: non_neg_integer(), name: String.t(), kind: kind()}

kind()

@type kind() :: :camera | :screen

Functions

list(opts \\ [])

@spec list(keyword()) :: {:ok, [device()]} | {:error, term()}

Ask ffmpeg for its video devices.

Returns {:error, {:no_avfoundation, output}} when ffmpeg's output has no device listing at all, which is what an ffmpeg without an AVFoundation input — any ffmpeg not built for macOS — produces. output is ffmpeg's own explanation.

Options

  • :executable — path to ffmpeg. Defaults to whatever is on $PATH.

parse(output)

@spec parse(String.t()) ::
  {:ok, [device()]} | {:error, {:no_avfoundation, String.t()}}

Read the video devices out of ffmpeg's -list_devices output.

iex> output = """
...> [AVFoundation indev @ 0x1] AVFoundation video devices:
...> [AVFoundation indev @ 0x1] [0] FaceTime HD Camera
...> [AVFoundation indev @ 0x1] [1] Capture screen 0
...> [AVFoundation indev @ 0x1] AVFoundation audio devices:
...> [AVFoundation indev @ 0x1] [0] MacBook Pro Microphone
...> """
iex> BB.Camera.AVF.Devices.parse(output)
{:ok,
 [
   %{index: 0, name: "FaceTime HD Camera", kind: :camera},
   %{index: 1, name: "Capture screen 0", kind: :screen}
 ]}