# `BB.Camera.AVF.Devices`
[🔗](https://github.com/beam-bots/bb_camera_avf/blob/main/lib/bb/camera/avf/devices.ex#L5)

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.

# `device`

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

# `kind`

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

# `list`

```elixir
@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`

```elixir
@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}
     ]}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
