ExCubecl.MediaPipeline behaviour (ExCubecl v0.4.0)

Copy Markdown View Source

A GenServer behaviour for real-time media processing pipelines.

Designed for livestreaming, camera effects, and other real-time use cases where frames are processed as they arrive.

Example

defmodule MyLivestream do
  use ExCubecl.MediaPipeline

  def handle_frame(frame, state) do
    frame
    |> ExCubecl.Filter.apply(:beauty_filter, strength: 0.5)
    |> ExCubecl.Video.overlay(state.logo, x: 10, y: 10)
    |> ExCubecl.Transcode.write_frame(state.encoder)
    {:ok, state}
  end
end

Callbacks

  • handle_frame/2 — called for each incoming frame. Receives the frame and current state, must return {:ok, new_state} or {:error, reason}.

Summary

Functions

Pushes a frame into the pipeline for processing.

Starts a media pipeline GenServer.

Callbacks

handle_frame(t, state)

@callback handle_frame(ExCubecl.VideoFrame.t(), state :: term()) ::
  {:ok, new_state :: term()} | {:error, term()}

Functions

push_frame(server, frame)

@spec push_frame(GenServer.server(), ExCubecl.VideoFrame.t()) :: :ok

Pushes a frame into the pipeline for processing.

start_link(module, init_arg, opts \\ [])

@spec start_link(module(), term(), keyword()) :: GenServer.on_start()

Starts a media pipeline GenServer.

Options

  • :name — register the process under a name
  • :source — media source path or reference
  • :encoder — encoder reference from Transcode.start/2