View Source Xav.Encoder (xav v0.10.0)

Audio/Video encoder.

Currently, it only supports video encoding:

  • h264
  • h265/hevc

Summary

Functions

Encodes a frame.

Flush the encoder.

Create a new encoder.

Types

@type codec() :: :h264 | :h265 | :hevc
@type encoder_options() :: Keyword.t()
@type t() :: reference()

Functions

@spec encode(t(), Xav.Frame.t()) :: [Xav.Packet.t()]

Encodes a frame.

The return value may be an empty list in case the encoder needs more frames to produce a packet.

@spec flush(t()) :: [Xav.Packet.t()]

Flush the encoder.

@spec new(codec(), Keyword.t()) :: t()

Create a new encoder.

It accepts the following options:

  • :width (pos_integer/0) - Required. Width of the video samples.

  • :height (pos_integer/0) - Required. Height of the video samples.

  • :format (atom/0) - Required. Pixel format of the video samples.

  • :time_base (tuple of pos_integer/0, pos_integer/0 values) - Required. Time base of the video stream.

    It is a rational represented as a tuple of two postive integers {numerator, denominator}. It represent the number of ticks denominator in numerator seconds. e.g. {1, 90000} reprensents 90000 ticks in 1 second.

    it is used for the decoding and presentation timestamps of the video frames. For video frames with constant frame rate, choose a timebase of {1, frame_rate}.

  • :gop_size (pos_integer/0) - Group of pictures length.

    Determines the interval in which I-Frames (or keyframes) are inserted in the stream. e.g. a value of 50, means the I-Frame will be inserted at the 1st frame, the 51st frame, the 101st frame, and so on.

  • :max_b_frames (non_neg_integer/0) - Maximum number of consecutive B-Frames to insert between non-B-Frames.

    A value of 0, disable insertion of B-Frames.

  • :profile (atom/0) - The encoder's profile.

    A profile defines the capabilities and features an encoder can use to target specific applications (e.g. live video)

    The following profiles are defined:

    CodecProfiles
    h264constrained_baseline, baseline, main, high
    h265/hevcmain, main_10, main_still_picture