Membrane.FFmpeg.Transcoder (Membrane FFmpeg Transcoder Plugin v1.7.0)

Copy Markdown View Source

Tasks as input an unparsed stream and provides on each pad an unparsed, transcoded stream with the desired properties.

Input might be MPEG-TS or FLV but other streaming containers might work as well. If the input stream contains more than 1 video and 1 audio stream, which one will be picked is undefined behaviour.

Process lifecycle

Each bin runs FFmpeg once. When the bin observes that process exiting, it sends its parent one notification:

{:transcoder_exited, %{reason: reason, input_eos_received?: boolean}}

reason is :normal for exit zero, {:status, code} for a nonzero exit, or {:signal, signal, core_dump?} for termination by signal. Infrastructure failures may carry another reason, such as :port_closed.

input_eos_received? records whether the FFmpeg filter had handled input EOS when it observed the exit. It is an observation, not a success classification. An exit can be abnormal even after input EOS; decoder warnings can also occur before a successful exit.

Process exit does not mean that the media outputs or downstream sinks have finished. The bin preserves output EOS for normal and abnormal FFmpeg exits, after its readers have drained. The notification and individual output EOS travel through different processes; callers must tolerate either arrival order and use downstream completion to coordinate draining.

The bin never restarts FFmpeg. Its parent owns recovery, drain deadlines, and any replacement run. Internal element/reader failures still use ordinary OTP failure propagation. The notification is not guaranteed during bin teardown or a bin crash; callers must also supervise or monitor their media graph.

Bin options

Passed via struct Membrane.FFmpeg.Transcoder.t/0

  • wait_random_access_indicator

    boolean()

    Default value: true
    If enabled, emits packets only after the random access indicator is found in the MPEG-TS PES stream, otherwise packets are emitted immediately. When enabled, it means that the first video packet that comes out is going to be a keyframe unit.

Pads

:input

Accepted formats:

Membrane.RemoteStream
Direction::input
Availability::always

:scte

Accepted formats:

Membrane.RemoteStream
Membrane.AAC
Membrane.H264
Direction::output
Availability::on_request

Pad options:

  • pid

    pos_integer()

    Default value: nil
    PID of the SCTE stream. When nil it grabs the first stream.

:text

Accepted formats:

Membrane.Text
Direction::output
Availability::on_request

Pad options:

  • source
    {:dvb_teletext, 100..899}
    Required
    Defines the source of the captions. Currently supported:
    • Teletext: {:dvb_teletext, page_number}

:video

Accepted formats:

Membrane.RemoteStream
Membrane.AAC
Membrane.H264
Direction::output
Availability::on_request

Pad options:

  • copy

    boolean()

    Default value: false
    If enabled, the stream will not be re-encoded

  • resolution

    {integer(), integer()}

    Default value: {-2, 720}
    Resolution of the given output.

  • bitrate

    pos_integer()

    Default value: 3300000
    Maximum bitrate

  • profile

    atom()

    Default value: :high
    H264 Profile

  • crf

    pos_integer()

    Default value: 26

  • preset

    atom()

    Default value: :high

  • tune

    atom()

    Default value: :zerolatency

  • fps

    pos_integer()

    Default value: 30

  • gop_size

    pos_integer()

    Default value: 60

  • b_frames

    pos_integer()

    Default value: 3

  • level

    String.t()

    Default value: "3.1"

:audio

Accepted formats:

Membrane.RemoteStream
Membrane.AAC
Membrane.H264
Direction::output
Availability::on_request

Pad options:

  • copy

    boolean()

    Default value: false
    If enabled, the stream will not be re-encoded

  • codec

    :aac | :opus

    Default value: :aac
    Audio codec to use for encoding. Ignored when copy is true.

  • bitrate

    pos_integer()

    Default value: 128000
    Maximum bitrate

  • sample_rate

    pos_integer()

    Default value: 48000

  • channels

    pos_integer()

    Default value: 2

Summary

Types

Options for pad :audio

Options for pad :scte

t()

Struct containing options for Membrane.FFmpeg.Transcoder

Options for pad :text

Options for pad :video

Functions

Returns description of options available for this module

Types

audio_pad_opts()

@type audio_pad_opts() :: [
  copy: boolean(),
  codec: :aac | :opus,
  bitrate: pos_integer(),
  sample_rate: pos_integer(),
  channels: pos_integer()
]

Options for pad :audio

scte_pad_opts()

@type scte_pad_opts() :: [{:pid, pos_integer()}]

Options for pad :scte

t()

@type t() :: %Membrane.FFmpeg.Transcoder{wait_random_access_indicator: boolean()}

Struct containing options for Membrane.FFmpeg.Transcoder

text_pad_opts()

@type text_pad_opts() :: [{:source, {:dvb_teletext, 100..899}}]

Options for pad :text

video_pad_opts()

@type video_pad_opts() :: [
  copy: boolean(),
  resolution: {integer(), integer()},
  bitrate: pos_integer(),
  profile: atom(),
  crf: pos_integer(),
  preset: atom(),
  tune: atom(),
  fps: pos_integer(),
  gop_size: pos_integer(),
  b_frames: pos_integer(),
  level: String.t()
]

Options for pad :video

Functions

options()

@spec options() :: keyword()

Returns description of options available for this module