OggVorbisParser v1.0.0 OggVorbisParser View Source

A parser for VorbisComments in Ogg containers.

While it's possible to use Vorbis streams without Ogg containers or with different kinds of containers, this parser expects Ogg. It might work for parsing the audio metadata in .ogv files, which are still Ogg containers with video streams and Vorbis streams, but this hasn't been tested enough.

The relevant part of an Ogg Vorbis file starts with an Ogg capture pattern (a file signature) followed by some Ogg container bits, the Vorbis identification header, and the Vorbis comment header.

OggVorbisParser looks for a comment header packet type of 3 immediately followed by the string "vorbis." This is the beginning of the comment header.

Version 0.1.0's output wasn't very convenient so parse/1 now gives back a nested map. Convert string keys to atoms at your own risk. If you know you'll always have certain comments for your files, e.g., "artist" or "title," consider using String.to_existing_atom/1.

Link to this section Summary

Functions

Parses VorbisComment if present.

Link to this section Functions

Link to this function

parse(filename)

View Source
parse(bitstring()) :: {:ok, map()} | {:error, :atom}

Parses VorbisComment if present.

Note that the "format" comment in the example below says MP3 because this Ogg file from archive.org was probably converted from an mp3. The actual mp3 is included too as shown below.

Examples

iex> {:ok, binary} = OggVorbisParser.parse("test/audio_files/lifeandtimesoffrederickdouglass_01_douglass.ogg")
iex> binary
%{
  "comments" => %{
    "album" => "Life and Times of Frederick Douglass",
    "artist" => "Frederick Douglass",
    "comment" =>
      "http://archive.org/details/life_times_frederick_douglass_ls_1411_librivox",
    "crc32" => "965da915",
    "encoder" => "Lavf55.45.100",
    "format" => "128Kbps MP3",
    "genre" => "speech",
    "height" => "0",
    "length" => "351.76",
    "md5" => "4be053d1a643c55f155bc489e687f9c8",
    "mtime" => "1415249910",
    "sha1" => "f85622a5998dde20e935fbcee782fcb39bbcdaa6",
    "size" => "5632957",
    "source" => "original",
    "title" => "01 - Author's Birth",
    "tracknumber" => "2",
    "vendor_string" => "Lavf55.45.100",
    "width" => "0"
  },
  "vendor_string" => "Lavf55.45.100"
}

iex> {:ok, binary} = OggVorbisParser.parse("test/audio_files/lifeandtimesoffrederickdouglass_01_douglass.ogg")
iex> binary["comments"]["title"]
"01 - Author's Birth"

iex> {:error, err} = OggVorbisParser.parse("test/audio_files/lifeandtimesoffrederickdouglass_01_douglass_128kb.mp3")
iex> err
:no_ogg_container_found