From TagLib#

Jump to: navigation, search

Discover TagLib#

TagLib# is a FREE, open source library for reading and writing tags to audio and video files.

Find out more about:

Free as in Speech

TagLib# is licensed under the GNU Lesser General Public License. This means you have a 100% full right to view the source, to use it in your project, to sell products using TagLib#! Any program, file reader, ID3v2 frame, MPEG4 box, etc you make is your own to do with as you please and you don't owe me a dime. (But I would gladly accept one.)

The only major issue is that you can't bundle the library in its original or modified form in a DLL or EXE that is not under the LGPL or a compatible license. This means you can still link to the library, still create your own subclasses of TagLib.File, etcetera, in whatever commercial or non-commercial license you like, but you've got to keep TagLib# as a separate DLL. The rationale behind this is protecting the rights of users, and if there is any conflict with your application, don't hesitate to contact me and we can work on a solution.

Supported Formats

TagLib# supports a wide variety of both audio and video formats. The default library provides some of the most common audio and video formats, but is extensible so a clever programmer could expand his program to use any format under the sun. HOWTO: Implement additional formats in TagLib Sharp

Format Extension Media Types Tag Types
Advanced Systems Format .asf, .wma, .wmv Audio, Video ASF Extended Content Description Objects
Audio Video Interleave (AVI) .avi Audio, Video RIFF INFO, MovieID, DivX, ID3v2 *
Free Lossless Audio Codec .flac Audio APEv2, ID3v1, ID3v2, Xiph Comments, FLAC Metadata (pictures)
MusePack .mpc, .mp+, .mpp Audio APEv2, ID3v1, ID3v2
MPEG Versions 1 - 2.5 .mpeg, .mpg, .mpe, .mpv2 Audio, Video APEv2, ID3v1, ID3v2
MPEG Audio .mp3 Audio APEv2, ID3v1, ID3v2
MPEG-4 .mp4, .m4a, .m4v, .m4p Audio, Video Apple ILST Box
OGG (Vorbis and Theora only) .ogg Audio, Video Xiph Comments **
Wave .wav Audio RIFF INFO, MovieID, DivX, ID3v2 *
WavPack .wv Audio APEv2, ID3v1, ID3v2

* ID3v2 tags are stored in a non-standard "ID32" chunk inside the file. As such, it should not be expected that other players will have access to information not stored in the other tagging formats, such as embedded images.

** Values will be read from each comment in the order their parent bitstreams appear in the file. However modified values will only be stored in the first bitstream.

Generic Tags

Knowing and understanding the 10 tag types used in TagLib# is something I don't even want to bother with. As such, many common tagging features have been added straight into the TagLib.Tag base class and are accessible by nothing more than file.Tag.SomeProperty.

Using these features, you could do almost anything in 10 lines of code or less:

 1 public class SetCoverImage
 2 {
 3     // Store the picture in the second argument in the file in the first argument.
 4     public static void Main (string [] args)
 5     {
 6         TagLib.File file = TagLib.File.Create (args [0]);
 7         file.Tag.Pictures = new TagLib.IPicture [] {new TagLib.Picture (args [1])};
 8         file.Save ();
 9     }
10 }

Below are the readily available tags in TagLib#:

Property Description Type How to Set
Title The title of the composition. string Title = "Waiting for the DJ";
AlbumArtists The primary artists who created the album or appear on the cover, or "Various Artists". string [] AlbumArtists = new string [] {"Talib Kweli"};
Performers The artists performed on this specific track. string [] Performers = new string [] {"Bilal",

"Talib Kweli", "Michael Rapaport"};

Composers The people who composed the music or wrote the lyrics. string [] Composers = new string [] {"B. Oliver",

"D. Darien", "Talib Kweli"};

Album The album the track appears in. string Album = "Quality";
Comment A user defined description of the current track. string Comment = "I like this one because...";
Genres Genres of music that the track/album belongs to. string [] Genres = new string [] {"Rap", "Hip-Hop"};
Year The year the album was released. uint Year = 2002;
Track The order in which the track appears in the album, or zero if albumless. uint Track = 6;
TrackCount The number of tracks in the album, or zero if unknown. uint TrackCount = 15;
Disc The order in which the disc appears in a boxed set, or zero if not a set. uint Disc = 1;
DiscCount The number of discs in a boxed set, or zero if unknown. uint DiscCount = 1;
Lyrics The lyrics or text transcription of the track. string Lyrics = "[Bilal]\r\nWaitin' for the DJ...";
Grouping The grouping that the current track belongs to. This could be an movement for classical music, or the part of the disc, or an empty string if unknown. string Grouping = "";
BeatsPerMinute The number of beats per minute, or zero if unknown. This is very useful for DJ's. uint BeatsPerMinute = 99;
Conductor The conductor for the track, or an empty string if unknown. string Conductor = "";
Copyright Copyright information for the track, or an empty string if unknown. string Copyright = "";
Pictures Pictures relevant to the current track. They can be cover images, inserts, the performers, the recording studio, etc. IPicture [] Pictures = new IPicture [] {

new Picture ("cover.png")};

But you are still able to access the more advanced components of tags...

Raw Power

TagLib# makes things simple, but it doesn't simplify away the stuff you really want to access. If you want to use ID3v2 relative volume adjustment or specify width and height for a FLAC picture, TagLib# still makes things easier than ever.

To access a specific tag from a file, you simply have to call something along the lines of the following:

TagLib.Id3v2.Tag id32_tag = file.GetTag (TagLib.TagTypes.Id3v2) as TagLib.Id3v2.Tag;

Once you have the tag, you merely have to call a tag specific function:

if (id32_tag != null) {
   TagLib.Id3v2.RelativeVolumeFrame rva = TagLib.Id3v2.RelativeVolumeFrame.Get
      (id32_tag, "My Adjustment", false);
   
   if (rva != null) {
       volume_adjustment = rva.VolumeAdjustment (TagLib.Id3v2.ChannelType.MasterVolume);
       peak_volume       = rva.PeakVolume       (TagLib.Id3v2.ChannelType.MasterVolume);
   }
}

Each format has its own features, so reviewing the API is a must, but the options are unlimited.