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

Membrane element providing parser for H264 encoded video stream.

The parser:

  • prepares and sends the appropriate stream format, 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 stream format 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 rewriting of timestamps:

  • in the :bytestream mode:
    • if option :framerate is set to nil, the output buffers have their :pts and :dts set to nil
    • if framerate is specified, :pts and :dts will be generated automatically, based on that framerate, starting from 0 This may only be used with h264 profiles :baseline and :constrained_baseline, where PTS==DTS.
  • 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. Its value will be sent inside the output Membrane.H264 stream format.

pads

Pads

input

:input

Accepted formats:

%RemoteStream{type: :bytestream}
%H264.RemoteStream{alignment: alignment} when alignment in [:nalu, :au]
Direction::input
Availability::always
Mode::pull
Demand mode::auto
Demand unit::buffers

output

:output

Accepted formats:

%H264{alignment: :au, nalu_in_metadata?: true}
Direction::output
Availability::always
Mode::pull
Demand mode::auto

Link to this section Summary

Types

t()

Struct containing options for Membrane.H264.Parser

Functions

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 options() :: keyword()

Returns description of options available for this module