ExMP4.FragDataWriter behaviour (MP4 Reader and Writer v0.11.0)

View Source

A behaviour module for implementing fragmented mp4 data writer.

Summary

Callbacks

Close the output.

Initialize the output.

Invoked to handle writing while seeking into the file.

Invoked to handle writing media header initialization.

Invoked to handle writing the whole segment.

Types

location()

@type location() :: :file.location() | nil

state()

@type state() :: any()

Callbacks

close(state)

@callback close(state()) :: :ok

Close the output.

open(input)

@callback open(input :: any()) :: {:ok, state()} | {:error, reason :: any()}

Initialize the output.

The returned state will be the first argument on the other callbacks.

write(state, data, location)

(optional)
@callback write(state(), data :: iodata(), location()) :: state()

Invoked to handle writing while seeking into the file.

This is an optional callback, only called by the ExMP4.FWriter to update the fragments duration in case mehd is present.

write_init_header(state, header)

@callback write_init_header(state(), header :: [ExMP4.Box.t()]) :: state()

Invoked to handle writing media header initialization.

The header is two element list with the first element being ftyp box and the second the moov box.

write_segment(state, segment)

@callback write_segment(state(), segment :: [ExMP4.Box.t()]) :: state()

Invoked to handle writing the whole segment.

The segment is a list of boxes that are part of the segment. The first boxes are sidx if present, then a moof box, followed by the mdat box containing the media data.