C++ library for reading and writing MP4/M4A/AAC (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Go to file
Martchus aed719bacf Fix usage of bibliographic language codes 2021-01-20 22:39:42 +01:00
aac Fix warning in AacSbrInfo 2019-06-20 22:56:49 +02:00
adts Mark all "final" tag, track and container classes as such 2020-12-18 21:13:52 +01:00
av1 Adapt to changes in c++utilities 2019-06-12 20:40:45 +02:00
avc Fix handling AVC config errors leading to crashes 2020-12-01 01:44:51 +01:00
avi Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
cmake/scripts Fix usage of bibliographic language codes 2021-01-20 22:39:42 +01:00
doc Improve refs in "Adding new fields" doc 2019-01-10 13:37:13 +01:00
flac Mark all "final" tag, track and container classes as such 2020-12-18 21:13:52 +01:00
id3 Mark all "final" tag, track and container classes as such 2020-12-18 21:13:52 +01:00
ivf Mark all "final" tag, track and container classes as such 2020-12-18 21:13:52 +01:00
matroska Mark all "final" tag, track and container classes as such 2020-12-18 21:13:52 +01:00
mp4 Mark all "final" tag, track and container classes as such 2020-12-18 21:13:52 +01:00
mpegaudio Mark all "final" tag, track and container classes as such 2020-12-18 21:13:52 +01:00
ogg Mark all "final" tag, track and container classes as such 2020-12-18 21:13:52 +01:00
opus Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
scripts Add script to update enum comments 2020-04-22 22:09:00 +02:00
testfiles Add MP4 testfile with chapters 2019-03-28 17:54:18 +01:00
tests Add Locale class to deal with differently specified languages/countries 2020-12-16 17:48:08 +01:00
vorbis Vorbis comment: Turn "YEAR" into "DATE" (unless "DATE" exists) 2020-11-25 01:39:57 +01:00
wav Mark all "final" tag, track and container classes as such 2020-12-18 21:13:52 +01:00
.gitignore Apply clang-format later 2017-05-01 03:19:44 +02:00
CMakeLists.txt Allow to specify location of JSON document for ISO-639-2 2021-01-20 21:59:34 +01:00
LICENSE Initial commit 2015-04-22 19:11:19 +02:00
README.md Generate code for ISO-639-2/B mapping from iso-codes package 2021-01-20 21:45:14 +01:00
abstractattachment.cpp Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
abstractattachment.h Adapt to c++utilities v5 2019-05-04 16:04:21 +02:00
abstractchapter.cpp Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
abstractchapter.h Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
abstractcontainer.cpp Adapt to changes in c++utilities 2019-06-12 20:40:45 +02:00
abstractcontainer.h Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
abstracttrack.cpp Add Locale class to deal with differently specified languages/countries 2020-12-16 17:48:08 +01:00
abstracttrack.h Improve documentation 2020-12-16 17:49:02 +01:00
aspectratio.cpp Adapt to c++utilities v5 2019-05-04 16:04:21 +02:00
aspectratio.h Make many constructors explicit to avoid unintended implicit conversions 2020-12-05 20:48:57 +01:00
backuphelper.cpp Don't suppress IO errors when writing files 2019-12-15 19:43:16 +01:00
backuphelper.h Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
basicfileinfo.cpp Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
basicfileinfo.h Make many constructors explicit to avoid unintended implicit conversions 2020-12-05 20:48:57 +01:00
caseinsensitivecomparer.h Apply clang-format 2018-03-07 01:17:50 +01:00
diagnostics.cpp Return name for DiagLevel::Debug 2020-12-01 01:51:27 +01:00
diagnostics.h Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
exceptions.cpp Improve documentation 2020-11-05 19:52:09 +01:00
exceptions.h Use noexcept directly 2019-02-17 17:14:07 +01:00
fieldbasedtag.h Adjust values()/setValues() to handle multiple values per text frame 2018-07-12 12:34:38 +02:00
genericcontainer.h Adapt to c++utilities v5 2019-05-04 16:04:21 +02:00
genericfileelement.h Use 64 KiB buffer to copy file elements 2019-12-30 23:51:54 +01:00
generictagfield.h Replace typedef with using 2018-07-12 12:34:38 +02:00
global.h Adapt to changes in c++utilities 2019-06-12 20:40:45 +02:00
localeawarestring.cpp Apply clang-format 2018-03-07 01:17:50 +01:00
localeawarestring.h Add Locale class to deal with differently specified languages/countries 2020-12-16 17:48:08 +01:00
localehelper.cpp Don't map language code "und" 2021-01-20 22:19:43 +01:00
localehelper.h Remove unused optional header from localehelper.h 2021-01-20 20:10:56 +01:00
margin.h Make many constructors explicit to avoid unintended implicit conversions 2020-12-05 20:48:57 +01:00
mediafileinfo.cpp Add Locale class to deal with differently specified languages/countries 2020-12-16 17:48:08 +01:00
mediafileinfo.h Make many constructors explicit to avoid unintended implicit conversions 2020-12-05 20:48:57 +01:00
mediaformat.cpp Include AVC profiles in abbreviations 2020-10-01 19:33:42 +02:00
mediaformat.h Distinguish text and "meta" tracks in MP4 2019-04-19 21:59:46 +02:00
positioninset.h Make many constructors explicit to avoid unintended implicit conversions 2020-12-05 20:48:57 +01:00
progressfeedback.cpp Document progress feedback 2018-06-03 20:32:35 +02:00
progressfeedback.h Make many constructors explicit to avoid unintended implicit conversions 2020-12-05 20:48:57 +01:00
settings.h Use helper for flag enum from c++utilities 2019-08-12 20:22:57 +02:00
signature.cpp Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
signature.h Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
size.cpp Apply clang-format 2018-03-07 01:17:50 +01:00
size.h Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
tag.cpp Add Tag::supportsMultipleValues() 2018-07-13 12:25:00 +02:00
tag.h Deprecate 'Year' in favor of 'RecordDate' and 'ReleaseDate', fix handling in ID3v2 2020-04-24 23:15:13 +02:00
tagtarget.cpp Adapt to changes in c++utilities 2019-06-10 23:11:39 +02:00
tagtarget.h Make many constructors explicit to avoid unintended implicit conversions 2020-12-05 20:48:57 +01:00
tagvalue.cpp Add Locale class to deal with differently specified languages/countries 2020-12-16 17:48:08 +01:00
tagvalue.h Add Locale class to deal with differently specified languages/countries 2020-12-16 17:48:08 +01:00

README.md

Tag Parser

C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags.

Supported formats

The tag library can read and write the following tag formats:

  • iTunes-style MP4/M4A tags (MP4-DASH is supported)
  • ID3v1 and ID3v2 tags
    • conversion between ID3v1 and different versions of ID3v2 is possible
  • Vorbis, Opus and FLAC comments in Ogg streams
    • cover art via "METADATA_BLOCK_PICTURE" is supported
  • Vorbis comments and "METADATA_BLOCK_PICTURE" in raw FLAC streams
  • Matroska/WebM tags and attachments

File layout options

Tag position

The library allows you to choose whether tags should be placed at the beginning or at the end of an MP4/Matroska file.

Padding

Padding allows adding additional tag information without rewriting the entire file or appending the tag. Usage of padding can be configured:

  • minimum/maximum padding: The file is rewritten if the padding would fall below/exceed the specifed limits.
  • preferred padding: If the file needs to be rewritten the preferred padding is used.

Default value for minimum and maximum padding is zero. Hence the library will almost always have to rewrite the entire file to apply changes. To prevent this, set at least the maximum padding to a higher value.

It is also possible to force rewriting the entire file always.

Taking advantage of padding is currently not supported when dealing with Ogg streams (it is supported when dealing with raw FLAC streams).

Additional features

The library can also display technical information such as the ID, format, language, bitrate, duration, size, timestamps, sampling frequency, FPS and other information of the tracks.

It also allows to inspect and validate the element structure of MP4 and Matroska files.

Text encoding, Unicode support

The library is aware of different text encodings and can convert between different encodings using iconv.

Windows specific

A workaround to support filenames containing non-ASCII characters (despite the lack of an UTF-8 supporting std::fstream under Windows) can be enabled by adding -DUSE_NATIVE_FILE_BUFFER=ON to the CMake arguments when building c++utilities. It is not sufficient to specify this option only when building tagparser.

Usage

This example shows how to read and write tag fields in a format-independent way:

#include <tagparser/mediafileinfo.h>
#include <tagparser/diagnostics.h>

// create a MediaFileInfo for high-level access to overall functionality of the library
TagParser::MediaFileInfo fileInfo;
// create container for errors, warnings, etc.
Diagnostics diag;

// open file (might throw ios_base::failure)
fileInfo.setPath("/path/to/some/file");
fileInfo.open();
// parse tags
// (might throw exception derived from TagParser::Failure for fatal parsing error or ios_base::failure for IO errors)
fileInfo.parseTags(diag);

// get first tag as an object derived from the Tag class
auto tag = fileInfo.tags().at(0);
// extract title and convert it to UTF-8 std::string
// (toString() might throw ConversionException)
auto title = tag->value(TagParser::KnownField::Title).toString(TagParser::TagTextEncoding::Utf8);

// change album using an encoding suitable for the tag format
tag->setValue(TagParser::KnownField::Album, TagParser::TagValue("some UTF-8 string", TagParser::TagTextEncoding::Utf8, tag->proposedTextEncoding()));

// create progress
TagParser::AbortableProgressFeedback progress([callback for status update], [callback for percentage-only updates]);

// apply changes to the file on disk
// (might throw exception derived from TagParser::Failure for fatal processing error or ios_base::failure for IO errors)
fileInfo.applyChanges(diag, progress);

Summary

  • The most important class is TagParser::MediaFileInfo providing access to everything else.
  • IO errors are propagated via standard std::ios_base::failure.
  • Fatal processing errors are propagated by throwing a class derived from TagParser::Failure.
  • All operations which might generate warnings, non-fatal errors, ... take a TagParser::Diagnostics object to store those messages.
  • All operations which can be aborted or provide progress feedback take a TagParser::AbortableProgressFeedback object for callbacks and aborting.
  • Field values are stored using TagParser::TagValue objects. Those objects erase the actual type similar to QVariant from the Qt framework. The documentation of TagParser::TagValue covers how different types and encodings are handled.

Further documentation

For more examples check out the command line interface of Tag Editor. API documentation can be generated using Doxygen with make tagparser_apidoc.

Bugs, stability

Bugs can be reported on GitHub.

It is recommend to create backups before editing because I can not test whether the library works with all kinds of files. (When forcing rewrite a backup is always created.)

Build instructions

The tagparser library depends on c++utilities and is built in the same way. It also depends on zlib, iso-codes and requires at least CMake 3.19. For checking integrity of testfiles, the OpenSSL crypto library is required.

TODOs

  • Support more formats (EXIF, PDF metadata, Theora, ...)
  • Support adding cue-sheet to FLAC files

More TODOs are tracked in the issue section at GitHub.