[Flac-dev] reading vorbis comments with FLAC++?

Joshua Kwan joshk at triplehelix.org
Fri Nov 7 22:56:20 PST 2003

Well, I'm quite frankly stumped. I'm writing a program that recurses
into directories and reads (among others) FLAC files and should be able
to read the vorbis comments ARTIST and TITLE from the file.

A while back, I was popen()ing to metaflac, because I didn't want to
mess with libFLAC. But now, it's the weekend, so I can mess around with
this. Here's the code in question:

bool getflac (struct Song* flac, const char* path)
  FLAC__StreamMetadata *md = FLAC__metadata_object_new (FLAC__METADATA_TYPE_STREAMINFO);

  if (FLAC__metadata_get_streaminfo(path, md))
    unsigned nc = 0, i;
    FLAC::Metadata::VorbisComment vc (md);

    nc = vc.get_num_comments();

    for (i = 0; i <= nc; i++)
      FLAC::Metadata::VorbisComment::Entry e;
      e = vc.get_comment(i);
      if (!strcmp(e.get_field_name(), "ARTIST"))
        flac->artist = e.get_field_value();
      else if (!strcmp(e.get_field_name(), "TITLE"))
        flac->title = e.get_field_value();
    return true;
    return false;

When I run this code, I get a SEGV during get_comment because
object_->data.vorbis_comment.comments is junk. Must I initialize it
somewhere? Note that vc.get_num_comments returns 14, which I imagine is
a correct number. The documentation isn't overly clear about how this works
and it would be cooler if some basic examples could be provided.

Thanks in advance for any help that can be provided. Excuse my
ignorance! :(

Joshua Kwan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://lists.xiph.org/pipermail/flac-dev/attachments/20031107/fcbc8514/attachment.pgp

More information about the Flac-dev mailing list