# `ExCubecl.Transcode`
[🔗](https://github.com/ohhi-vn/ex_cubecl/blob/v0.4.0/lib/ex_cubecl/transcode.ex#L1)

Encode and mux media output.

Supports file-to-file transcoding and frame-by-frame streaming encoding.

## File-to-file transcode

    ExCubecl.Transcode.run("input.mp4", "output.mp4",
      video: [codec: :h264, bitrate: "4M", fps: 30],
      audio: [codec: :aac, bitrate: "192k", sample_rate: 48000]
    )

## Frame-by-frame streaming transcode

    {:ok, enc} = ExCubecl.Transcode.start("output.mp4",
      video: [codec: :h265, width: 1280, height: 720],
      audio: [codec: :aac]
    )

    ExCubecl.Transcode.write_frame(enc, processed_video_frame)
    ExCubecl.Transcode.write_samples(enc, processed_audio_samples)
    ExCubecl.Transcode.finish(enc)

## Supported codecs

Video: h264, h265, vp9, av1, prores
Audio: aac, opus, mp3, flac, pcm

## Supported containers

mp4, mkv, webm, mov, ts

# `encoder`

```elixir
@type encoder() :: reference()
```

# `finish`

```elixir
@spec finish(encoder()) :: :ok | {:error, term()}
```

Finalizes encoding and closes the output file.

# `run`

```elixir
@spec run(String.t(), String.t(), keyword()) :: :ok | {:error, term()}
```

Transcodes an input file to an output file with the specified options.

This is a convenience wrapper that opens the input, reads frames, applies
encoding, and writes the output.

## Options

  * `:video` — keyword list with `:codec`, `:bitrate`, `:fps`, `:width`, `:height`
  * `:audio` — keyword list with `:codec`, `:bitrate`, `:sample_rate`

# `start`

```elixir
@spec start(
  String.t(),
  keyword()
) :: {:ok, encoder()} | {:error, term()}
```

Starts a streaming transcoder for frame-by-frame encoding.

Returns an encoder reference to be used with `write_frame/2`, `write_samples/2`,
and `finish/1`.

## Options

  * `:video` — keyword list with `:codec`, `:width`, `:height`, `:bitrate`, `:fps`
  * `:audio` — keyword list with `:codec`, `:bitrate`, `:sample_rate`

# `write_frame`

```elixir
@spec write_frame(encoder(), ExCubecl.VideoFrame.t()) :: :ok | {:error, term()}
```

Writes a video frame to the encoder.

# `write_samples`

```elixir
@spec write_samples(encoder(), ExCubecl.AudioSamples.t()) :: :ok | {:error, term()}
```

Writes audio samples to the encoder.

---

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