Alex
Alex

Reputation: 1

Writing ID3v2 metadata using TagLib

I am writing a music ripper and have been at it for some days now. Everything is working as it should except setting metadata. I am downloading raw PCM data, encoding to MP3 using ffmpeg.exe and then setting metadata to the file. I know ffmpeg.exe can write metadata but it does not suit my needs as i cannot write the character (") when specifying the metadata in the command line. Also, ffmpeg.exe cuts my data to a maximum of 30 characters, which also is my problem when using TagLib:

TagLib::FileRef f("some_mp3.mp3");

f.tag()->setArtist("Loooooooooooooooooooooooooooooooooooong Artist");
f.tag()->setAlbum("Loooooooooooooooooooooooooooooooooooong Album");
f.tag()->setTitle("Loooooooooooooooooooooooooooooooooooong Title");
f.tag()->setTrack(37);

f.save();

It seems this code is using ID3v1 since it crops the long strings to just 30 characters, yes i did read some Wikipedia on this :P I need it to use ID3v2 to give long data. Any thoughts?

Upvotes: 0

Views: 1806

Answers (2)

Darokthar
Darokthar

Reputation: 1113

As i get it from the ffmpeg documentation ffmpeg.exe uses the lame codec. Thus you might want to check how to configure lame instead of ffmpeg. Lame has options for ID3 Tags, take a look hat their homepage here: http://lame.cvs.sourceforge.net/viewvc/lame/lame/USAGE

Upvotes: 1

LoSciamano
LoSciamano

Reputation: 1119

You can use the class TagLib::MPEG::File to open the file and the ID3v2Tag to get the ID3v2 tag. Your code will become this:

  TagLib::MPEG::File f("some_mp3.mp3");
  f.ID3v2Tag()->setArtist("Loooooooooooooooooooooooooooooooooooong Artist");
  f.ID3v2Tag()->setAlbum("Loooooooooooooooooooooooooooooooooooong Album");
  f.ID3v2Tag()->setTitle("Loooooooooooooooooooooooooooooooooooong Title");
  f.ID3v2Tag()->setTrack(37);
  f.save();

Hope this helps

Upvotes: 0

Related Questions