Membrane VideoMixer Plugin

Mixes multiple video inputs to a single output using ffmpeg filters. Allows dynamic input quality switches and source addition-removal while running.

This element is used in production.

Behavior and Policy

Core Mixing Policy

The mixer implements a strict synchronization policy: output frames are produced only when all required input pads have frames ready. This ensures deterministic, gap-free mixing without fallback frames.

Key Behaviors

Synchronization and Draining

Spec Changes

Pad Options

Primary Pad (:primary)

Dynamic Input Pads (:input)

Removed Options

The following options were removed in favor of the simpler synchronization policy:

Benefits of the Current Policy

The strict synchronization policy provides several advantages:

  1. Predictable behavior: Output is produced only when all required inputs are ready, eliminating timing-dependent edge cases.
  2. No visual artifacts: No black frames or frozen frames from caching, ensuring clean output.
  3. Simpler implementation: ~150 lines of complexity removed (fallback frames, black frame generation, last frame caching, delay logic).
  4. Memory bounded: Automatic draining prevents unbounded queue growth.
  5. Clear backpressure: When an input stops, mixing stops, making issues immediately visible.

Migration from Previous Versions

If you're upgrading from a version that supported delay or extra_queue_size:

Removed: Primary Delay

Old behavior: The :primary pad accepted a :delay option to buffer frames before mixing.

New behavior: Mixing starts immediately when all required pads have frames. If you need startup delay, implement it upstream of the mixer.

Removed: Black Frames and Frame Caching

Old behavior: When an input hadn't sent its first frame, a black frame was used. When an input paused, its last frame was reused.

New behavior: The mixer waits for all required inputs to have frames. No output is produced until all required pads are ready. If you need fallback behavior, handle it in your layout_builder by conditionally excluding pads from the layout.

Removed: Extra Queue Size

Old behavior: The :input pads accepted an :extra_queue_size option to limit buffering when the primary stalled.

New behavior: Non-required frames are automatically drained. No configuration needed.

Installation

def deps do
  [
    {:membrane_video_mixer_plugin, "~> 1.0.0"}
  ]
end

Copyright and License

Copyright 2022, KIM Keep In Mind GmbH Licensed under the Apache License, Version 2.0