# `PhoenixReplay.Export`
[🔗](https://github.com/elixir-vibe/phoenix_replay/blob/v0.6.2/lib/phoenix_replay/export.ex#L1)

Exports recordings as videos of the replayed page and the pointer.

A recording holds no pixels: the player renders it again from recorded
assigns. An export does the same in a headless browser and films it.

  1. `PhoenixReplay.Export.Schedule` plans the video: a constant frame
     rate from the first render, idle stretches shortened, and a
     screenshot only where the picture changes.
  2. `PhoenixReplay.Export.Screenshots` loads the replay into Chromium through
     [`playwright_ex`](https://hexdocs.pm/playwright_ex), at the recorded
     viewport and pixel ratio, steps it through the plan with the
     player's own pointer overlay, and screenshots each change.
  3. `PhoenixReplay.Export.Encoder` encodes the screenshots with `ffmpeg`
     into an H.264 MP4, run by [MuonTrap](https://hexdocs.pm/muontrap) so it
     never outlives the export.

The browser loads the replay from `PhoenixReplay.Web.Export.Endpoint`, a
private endpoint on 127.0.0.1 started with the first export, so it
needs no route or login in your app.

Exports wait their turn in a `PhoenixReplay.Export.Queue`: by default
`PhoenixReplay.Export.Queue.Local`, in memory, one at a time or
`:max_concurrency` at once; or `PhoenixReplay.Export.Queue.Oban`, in
your Oban queue. Each job's progress is broadcast; the player's **Export
video** and `mix phoenix_replay.export` both follow it. Finished videos
are deleted after `:ttl`.

## Setup

Add `{:playwright_ex, "~> 0.14"}` and `{:muontrap, "~> 1.6"}`, install
Playwright's Chromium (`npx playwright install chromium`) and `ffmpeg`,
and name your endpoint. MuonTrap runs on Linux and macOS.

    config :phoenix_replay, export: [endpoint: MyAppWeb.Endpoint]

See `:export` in `PhoenixReplay.Config` for the other options. Only
saved recordings are exported, not sessions still running.

# `unavailable`

```elixir
@type unavailable() ::
  :disabled | :no_endpoint | :no_playwright | :no_muontrap | :no_ffmpeg
```

Why exporting is not possible.

# `available`

```elixir
@spec available(PhoenixReplay.Config.t()) :: :ok | {:error, unavailable()}
```

Whether videos can be exported with `config`, or why not.

# `available?`

```elixir
@spec available?(PhoenixReplay.Config.t()) :: boolean()
```

Whether videos can be exported with `config`.

# `cancel`

```elixir
@spec cancel(PhoenixReplay.Export.Job.id(), PhoenixReplay.Config.t()) :: :ok
```

Cancels an export that is queued or running. A running one closes its
browser and stops encoding first, and ends `:cancelled`.

# `describe`

```elixir
@spec describe(unavailable()) :: String.t()
```

Explains why exporting is not possible.

# `get`

```elixir
@spec get(PhoenixReplay.Export.Job.id(), PhoenixReplay.Config.t()) ::
  PhoenixReplay.Export.Job.t() | nil
```

The export with `id`, if it is still kept.

# `latest`

```elixir
@spec latest(PhoenixReplay.Recording.id(), PhoenixReplay.Config.t()) ::
  PhoenixReplay.Export.Job.t() | nil
```

The latest export of a recording, if one is kept.

# `start`

```elixir
@spec start(
  PhoenixReplay.Recording.id(),
  PhoenixReplay.Config.t(),
  PhoenixReplay.Export.Options.t() | nil
) :: {:ok, PhoenixReplay.Export.Job.t()} | {:error, unavailable()}
```

Exports a saved recording with `options`, by default those the
configuration sets, or returns the export of it already queued or
running. See `PhoenixReplay.Export.Options`.

# `subscribe`

```elixir
@spec subscribe(PhoenixReplay.Recording.id()) :: :ok | {:error, term()}
```

Subscribes the caller to the exports of a recording: each change to one
arrives as `{PhoenixReplay.Export, %PhoenixReplay.Export.Job{}}`.

---

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