View Source Membrane.H264.Parser (Membrane H264 plugin v0.1.0)

Membrane element providing parser for H264 encoded video stream.

The parser:

  • prepares and sends the appropriate caps, based on information provided in the stream and via the element's options
  • splits the incoming stream into h264 access units - each buffer being output is a Membrane.Buffer struct with a binary payload of a single access unit
  • enriches the output buffers with the metadata describing the way the access unit is split into NAL units, type of each NAL unit making up the access unit and the information if the access unit hold a keyframe.

The parser works in one of three possible modes, depending on the structure of the input buffers:

  • :bytestream - each input buffer contains some part of h264 stream's payload, but not necessary a logical h264 unit (like NAL unit or an access unit). Can be used for i.e. for parsing the stream read from the file.
  • :nalu_aligned - each input buffer contains a single NAL unit's payload
  • :au_aligned - each input buffer contains a single access unit's payload

The parser's mode is set automatically, based on the input caps received by that element:

  • Receiving %Membrane.RemoteStream{type: :bytestream} results in the parser mode being set to :bytestream
  • Receiving %Membrane.H264.RemoteStream{alignment: :nalu} results in the parser mode being set to :nalu_aligned
  • Receiving %Membrane.H264.RemoteStream{alignment: :au} results in the parser mode being set to :au_aligned

The distinguishment between parser modes was introduced to eliminate the redundant operations and to provide a reliable way for timestamps rewritting:

  • in the :bytestream mode, the output buffers have their :pts and :dts set to nil
  • in the :nalu_aligned mode, the output buffers have their :pts and :dts set to :pts and :dts of the input buffer that was holding the first NAL unit making up given access unit (that is being sent inside that output buffer).
  • in the :au_aligned mode, the output buffers have their :pts and :dts set to :pts and :dts of the input buffer (holding the whole access unit being output)

element-options

Element options

Passed via struct Membrane.H264.Parser.t/0

  • sps

    binary()

    Default value: ""
    Sequence Parameter Set NAL unit binary payload - if absent in the stream, should be provided via this option.

  • pps

    binary()

    Default value: ""
    Picture Parameter Set NAL unit binary payload - if absent in the stream, should be provided via this option.

  • framerate

    {pos_integer(), pos_integer()} | nil

    Default value: nil
    Framerate of the video, represented as a tuple consisting of a numerator and the denominator. It's value will be sent inside the output Membrane.H264 caps.

pads

Pads

input

:input

Availability :always
Caps Membrane.RemoteStream, restrictions:
  type: :bytestream,
Membrane.H264.RemoteStream, restrictions:
  alignment: one_of([:nalu, :au])
Demand mode :auto
Demand unit :buffers
Direction :input
Mode :pull
Name :input

output

:output

Availability :always
Caps Membrane.H264, restrictions:
  alignment: :au,
  nalu_in_metadata?: true
Demand mode :auto
Demand unit :buffers
Direction :output
Mode :pull
Name :output

Link to this section Summary

Types

t()

Struct containing options for Membrane.H264.Parser

Functions

Returns pads descriptions for Membrane.H264.Parser

Returns description of options available for this module

Link to this section Types

@type t() :: %Membrane.H264.Parser{
  framerate: {pos_integer(), pos_integer()} | nil,
  pps: binary(),
  sps: binary()
}

Struct containing options for Membrane.H264.Parser

Link to this section Functions

@spec membrane_pads() :: [{Membrane.Pad.name_t(), Membrane.Pad.description_t()}]

Returns pads descriptions for Membrane.H264.Parser

@spec options() :: keyword()

Returns description of options available for this module