ExMP4.FWriter (MP4 Reader and Writer v0.11.0)
View SourceModule responsible for writing fragmented MP4.
Summary
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(), [iodata()]}}, current_segments: %{required(integer()) => ExMP4.Box.Sidx.t()}, 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() }
@type writer_options() :: any()
Functions
@spec close(t()) :: :ok
Close the writer.
Create a new empty fragment.
After adding samples, the fragment should be finalized, with flush_fragment/1
.
Creates a new media segment.
Calling this function is optional. If not called, no Segment Index Box (sidx
) will be added.
Segments and Fragments
Current implementation restricts each segment to contain exactly one fragment.
This is why there is no separate flush_segment
function - the segment is automatically closed
when the single fragment is completed.
Finalizes the current fragment and segment (if any).
@spec new(writer_options(), [ExMP4.Track.t()], new_opts(), module()) :: {:ok, t()} | {:error, term()}
Create a new fragmented mp4 writer.
The tracks are assigned an id starting from 1.
The following options can be provided:
major_brand
- Set the major brandcompatible_brands
- Set the compatible brandscreation_time
- Set the creation timemodification_time
- Set the modification timeduration
- Set the total duration if known. The value can betrue
,false
or an integer.If
true
, the total duration of the presentation is calculated when closing thewriter
and themehd
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 themehd
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 themehd
box.moof_base_offset
- iftrue
, it indicates that thebase‐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
.
@spec new!(writer_options(), [ExMP4.Track.t()], new_opts(), module()) :: t()
The same as new/2
, but raises if it fails.
@spec track(t(), integer() | atom()) :: ExMP4.Track.t() | nil
Get a track by id or type.
@spec write_sample(t(), ExMP4.Sample.t()) :: t()
Write a sample to the current fragment.