View Source ExMP4.FWriter (MP4 Reader and Writer v0.6.0)

Module responsible for writing fragmented MP4.

Summary

Types

Options to supply when creating the writer.

t()

Functions

Close the writer.

Create a new empty fragment.

Flush the current fragment.

Create a new mp4 writer that writes to filesystem.

Write a sample to the current fragment.

Types

@type new_opts() :: [
  major_brand: binary(),
  compatible_brands: [binary()],
  minor_version: integer(),
  creation_time: DateTime.t(),
  modification_time: DateTime.t(),
  duration: integer() | boolean(),
  moof_base_offset: boolean()
]

Options to supply when creating the writer.

@type t() :: %ExMP4.FWriter{
  base_data_offset: integer(),
  current_fragments: %{required(integer()) => ExMP4.Box.Traf.t()},
  fragments_data: %{required(integer()) => [binary()]},
  ftyp_box_size: integer(),
  moof_base_offset: boolean(),
  movie_box: ExMP4.Box.Moov.t() | nil,
  sequence_number: integer(),
  tracks: %{required(integer()) => ExMP4.Track.t()},
  writer_mod: module(),
  writer_state: term()
}

Functions

@spec close(t()) :: :ok

Close the writer.

@spec create_fragment(t()) :: t()

Create a new empty fragment.

After adding samples, the fragment should be flashed, with flush_fragment/1.

@spec flush_fragment(t()) :: t()

Flush the current fragment.

Link to this function

new(filename, tracks, opts \\ [], module \\ ExMP4.FragDataWriter.File)

View Source
@spec new(Path.t(), [ExMP4.Track.t()], new_opts(), module()) ::
  {:ok, t()} | {:error, term()}

Create a new mp4 writer that writes to filesystem.

The tracks are assigned an id starting from 1.

The following options can be provided:

  • major_brand - Set the major brand

  • compatible_brands - Set the compatible brands

  • creation_time - Set the creation time

  • modification_time - Set the modification time

  • duration - Set the total duration if known. The value can be true, false or an integer.

    If true, the total duration of the presentation is calculated when closing the writer and the mehd box is set to include the fragment duration. Note that this needs the output target to support seeking (not suitable for live streaming.)

    If false, the total duration is not calculated and the mehd box is not included. This is suitable for real time or for presentations where the total duration is not available.

    If an integer, it's the total duration in the movie timescale and it'll be set in the mehd box.

  • moof_base_offset - if true, it indicates that the base‐data‐offset for the track fragments is the position of the first byte of the enclosing Movie Fragment Box. Defaults to: false.

The last argument is an optional module implementing ExMP4.FragDataWriter.

Link to this function

new!(filepath, tracks, opts \\ [], module \\ ExMP4.FragDataWriter.File)

View Source
@spec new!(Path.t(), [ExMP4.Track.t()], new_opts(), module()) :: t()

The same as new/2, but raises if it fails.

Link to this function

write_sample(writer, sample)

View Source
@spec write_sample(t(), ExMP4.Sample.t()) :: t()

Write a sample to the current fragment.