ExMP4.Helper (MP4 Reader and Writer v0.11.0)

View Source

Helper functions.

Summary

Functions

Format a millisecond duration as H:MM:ss.mmm

Convert duration between different timescales.

Types

timescale()

@type timescale() ::
  :nanosecond | :microsecond | :millisecond | :second | integer() | Ratio.t()

Functions

format_duration(duration_ms)

@spec format_duration(non_neg_integer()) :: String.t()

Format a millisecond duration as H:MM:ss.mmm

iex> ExMP4.Helper.format_duration(100)
"0:00:00.100"

iex> ExMP4.Helper.format_duration(165_469_850)
"45:57:49.850"

timescalify(time, timescale, timescale, rounding \\ :round)

@spec timescalify(Ratio.t() | integer(), timescale(), timescale(), :round | :exact) ::
  integer() | float()

Convert duration between different timescales.

iex> ExMP4.Helper.timescalify(1900, 90000, :millisecond)
21

iex> ExMP4.Helper.timescalify(21, :millisecond, 90_000)
1890

iex> ExMP4.Helper.timescalify(10, Ratio.new(30_000, 1001), Ratio.new(40, 2))
7

iex> ExMP4.Helper.timescalify(1600, :millisecond, :second)
2

iex> ExMP4.Helper.timescalify(15, :nanosecond, :nanosecond)
15

iex> ExMP4.Helper.timescalify(15000, Ratio.new(30_000, 1001), :second, :exact)
500.5