OggVorbisParser v2.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.
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 uses File.stream!/3 instead of File.read/1 to avoid loading entire audio files into memory.
Link to this section Summary
Functions
Parses VorbisComment if present. Only loads max_size_chunk_in_bytes into memory instead of the whole file. The default max_size_chunk_in_bytes is 4000 per xiph.org's recommended max header size for streaming.
Link to this section Functions
Parses VorbisComment if present. Only loads max_size_chunk_in_bytes into memory instead of the whole file. The default max_size_chunk_in_bytes is 4000 per xiph.org's recommended max header size for streaming.
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