ISOBMFF language unpacker v0.1.0 ISOBMFFLang View Source

ISO based media file format derived formats such as Apples MOV and MPEG’s MP4 pack language infromation in 16bit binaries. How these language codes are packed varies though from format to format, Apple has a table of QuickTime language codes that they enforce in the MOV format while MP4 uses a technique of packing 3 character ISO 639-2/T language codes into 3 unsigned 5 bit integers that they then shift and add.

Sounds complicated? You would be right, this hex is meant to abstract away the complexity and get right down to business.

At your disposal you have several convenience functions, they all do the same thing but take different types of input. If you have the language int packed as a 16 bit bitstring straight from a MP4 container use #int16_to_lang, if you’ve unpacked it to a Elixir integer use #int_to_lang or if you are presented with the raw 15 bit bitstring use #int15_to_lang. You get the picture the result will always be the same.

Examples

# QuickTime language code value for swedish (MOV container)
iex> ISOBMFFLang.int_to_lang(5)
{:ok, "swe"}

# Packed ISO Language Code for undefined language (MP4 container)
iex> ISOBMFFLang.int16_to_lang(<<0::1, 21956::15>>)
{:ok, "und"}

Link to this section Summary

Functions

Converts a 15 bit ISOBMFF integer language representation into ISO 639-2 language code

Converts a 16 bit, zero padded, uint15 ISOBMFF language representation into ISO 639-2 language code

Converts a 15 bit ISOBMFF integer language representation into ISO 639-2 language code

Link to this section Functions

Converts a 15 bit ISOBMFF integer language representation into ISO 639-2 language code.

Returns an error if integer value is not within range for a uint15

Examples

# QuickTime language code value for swedish (MOV container)
iex> ISOBMFFLang.int15_to_lang(<<5::15>>)
{:ok, "swe"}

# Packed ISO Language Code for undefined language (MP4 container)
iex> ISOBMFFLang.int15_to_lang(<<21956::15>>)
{:ok, "und"}

iex> ISOBMFFLang.int15_to_lang(<<1::14>>)
{:error, "Failed to parse 15 bit integer value: Integer out of bounds."}

iex> ISOBMFFLang.int15_to_lang(<<32768::17>>)
{:error, "Failed to parse 15 bit integer value: Integer out of bounds."}

Converts a 16 bit, zero padded, uint15 ISOBMFF language representation into ISO 639-2 language code.

Returns an error if integer value is not within range for a uint15

Examples

# QuickTime language code value for swedish (MOV container)
iex> ISOBMFFLang.int16_to_lang(<<0::1, 5::15>>)
{:ok, "swe"}

# Packed ISO Language Code for undefined language (MP4 container)
iex> ISOBMFFLang.int16_to_lang(<<0::1, 21956::15>>)
{:ok, "und"}

iex> ISOBMFFLang.int16_to_lang(<<-1::14>>)
{:error, "Failed to parse 16 bit integer value: Integer out of bounds."}

iex> ISOBMFFLang.int16_to_lang(<<32768::17>>)
{:error, "Failed to parse 16 bit integer value: Integer out of bounds."}

Converts a 15 bit ISOBMFF integer language representation into ISO 639-2 language code.

Returns an error if integer value is not within range for a uint15

Examples

# QuickTime language code value for swedish (MOV container)
iex> ISOBMFFLang.int_to_lang(5)
{:ok, "swe"}

# Packed ISO Language Code for undefined language (MP4 container)
iex> ISOBMFFLang.int_to_lang(21956)
{:ok, "und"}

iex> ISOBMFFLang.int_to_lang(-1)
{:error, "Failed to parse integer value: Integer out of bounds."}

iex> ISOBMFFLang.int_to_lang(32768)
{:error, "Failed to parse integer value: Integer out of bounds."}