View Source ExMP4.FWriter (MP4 Reader and Writer v0.6.0)
Module 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()}, 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.
Create a new empty fragment.
After adding samples, the fragment should be flashed, with flush_fragment/1
.
Flush the current fragment.
new(filename, tracks, opts \\ [], module \\ ExMP4.FragDataWriter.File)
View SourceCreate 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 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
.
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.
@spec write_sample(t(), ExMP4.Sample.t()) :: t()
Write a sample to the current fragment.