View Source Xav.Decoder (xav v0.10.0)

Audio/video decoder.

Summary

Types

Supported codecs.

t()

Functions

Decodes an audio/video frame.

Flushes the decoder.

Same as flush/1 but raises an exception on error.

Creates a new decoder.

Types

@type codec() :: atom()

Supported codecs.

To get the list of available decoders see Xav.list_decoders/0.

@type t() :: reference()

Functions

Link to this function

decode(decoder, data, opts \\ [])

View Source
@spec decode(t(), binary(), pts: integer(), dts: integer()) ::
  :ok | {:ok, Xav.Frame.t()} | {:error, atom()}

Decodes an audio/video frame.

Some video frames are meant for decoder only and will not contain actual video samples. Some audio frames might require more data to be converted to the desired output format. In both cases, :ok term is returned and more data needs to be provided.

@spec flush(t()) :: {:ok, [Xav.Frame.t()]} | {:error, atom()}

Flushes the decoder.

Flushing signals end of stream and forces the decoder to return the buffered frames if there're any.

Same as flush/1 but raises an exception on error.

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

Creates a new decoder.

codec is any audio/video decoder supported by FFmpeg.

opts can be used to specify desired output parameters:

  • :out_format (atom/0) - Output format of the samples.

    In case of video, it's the pixel format. In case of audio, it's the sample format.

    To get the list of supported pixel formats use Xav.pixel_formats/0, and for sample formats Xav.sample_formats/0.

  • :out_sample_rate (pos_integer/0) - Audio sample rate.

    If not specified, the sample rate of the input stream will be used.

  • :out_channels (pos_integer/0) - Number of audio channels.

    If not specified, the number of channels of the input stream will be used.

    Audio samples are always in the packed form - samples from different channels are interleaved in the same, single binary:

    <<c10, c20, c30, c11, c21, c31, c12, c22, c32>>

    An alternative would be to return a list of binaries, where each binary represents different channel:

    [
      <<c10, c11, c12, c13, c14>>,
      <<c20, c21, c22, c23, c24>>,
      <<c30, c31, c32, c33, c34>>
    ]
  • :out_width (pos_integer/0) - Scale the output video frame to the provided width.

  • :out_height (pos_integer/0) - Scale the output video frame to the provided height.