ExMP4.Writer (MP4 Reader and Writer v0.10.0)

View Source

This module contains functions to write MP4.

Summary

Functions

Add a new track.

Add multiple tracks.

Create a new mp4 writer that writes to filesystem.

Get a track by id or type.

Get all the available tracks.

Write the mp4 header.

Write the trailer and close the stream.

Types

new_opts()

@type new_opts() :: [{:fast_start, boolean()}]

t()

@type t() :: %ExMP4.Writer{
  current_chunk: %{required(non_neg_integer()) => {[iodata()], integer()}},
  fast_start: boolean(),
  ftyp_size: integer(),
  mdat_size: integer(),
  next_track_id: term(),
  tracks: %{required(non_neg_integer()) => ExMP4.Track.t()},
  writer_mod: module(),
  writer_state: any()
}

Functions

add_track(writer, track)

@spec add_track(t(), ExMP4.Track.t()) :: t()

Add a new track.

A track is created by instantiating the public fields of ExMP4.Track. The id is assigned by the writer and it's equals to the index of the track starting from 1. The first track has an id 1, the second 2, ...etc.

add_tracks(writer, tracks)

@spec add_tracks(t(), [ExMP4.Track.t()]) :: t()

Add multiple tracks.

new(filepath, opts \\ [], module \\ ExMP4.DataWriter.File)

Create a new mp4 writer that writes to filesystem.

The following options can be provided:

  • fast_start - Move the moov box to the beginning of the file. Defaults to: false

By default the writer writes the data to the file system, this behaviour can be changed by providing a module implementing ExMP4.DataWriter in the third argument.

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

@spec new!(Path.t(), new_opts(), module()) :: t()

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

track(writer, id_or_type)

@spec track(t(), integer() | atom()) :: ExMP4.Track.t() | nil

Get a track by id or type.

tracks(writer)

@spec tracks(t()) :: [ExMP4.Track.t()]

Get all the available tracks.

update_track(writer, track_id, opts)

@spec update_track(t(), ExMP4.Track.id(), Keyword.t()) :: t()

Update a track.

Only the following fields can be updated: type media media_tag width height sample_rate channels priv_data

write_header(writer, opts \\ [])

@spec write_header(t(), Keyword.t()) :: t()

Write the mp4 header.

This function should be called first before adding tracks.

write_sample(writer, sample)

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

Write a sample.

write_trailer(writer, opts \\ [])

Write the trailer and close the stream.