C++ library for reading and writing MP4/M4A/AAC (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Go to file
Martchus e81c6bb169 Implement small TODOs for v8 2018-07-12 12:34:38 +02:00
aac Disable (so far) unused unsignedCb 2018-06-05 22:40:02 +02:00
adts Use constexpr where possible 2018-07-12 12:34:38 +02:00
avc Use constexpr where possible 2018-07-12 12:34:38 +02:00
avi Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
flac Implement small TODOs for v8 2018-07-12 12:34:38 +02:00
id3 Implement small TODOs for v8 2018-07-12 12:34:38 +02:00
matroska Implement small TODOs for v8 2018-07-12 12:34:38 +02:00
mp4 Implement small TODOs for v8 2018-07-12 12:34:38 +02:00
mpegaudio Use constexpr where possible 2018-07-12 12:34:38 +02:00
ogg Implement small TODOs for v8 2018-07-12 12:34:38 +02:00
opus Use constexpr where possible 2018-07-12 12:34:38 +02:00
scripts Don't generate testfiles during testrun 2018-07-11 12:02:30 +02:00
testfiles Test more methods of MediaFileInfo 2017-08-17 18:44:11 +02:00
tests Don't use global variable for backup directory 2018-07-12 12:34:38 +02:00
vorbis Use constexpr where possible 2018-07-12 12:34:38 +02:00
wav Use constexpr where possible 2018-07-12 12:34:38 +02:00
.gitignore Apply clang-format later 2017-05-01 03:19:44 +02:00
CMakeLists.txt Preserve multiple strings in ID3v2 text frames 2018-07-12 12:34:38 +02:00
LICENSE Initial commit 2015-04-22 19:11:19 +02:00
README.md Document usage, especially error handling 2018-03-06 23:50:40 +01:00
abstractattachment.cpp Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
abstractattachment.h Apply clang-format 2018-03-07 01:17:50 +01:00
abstractchapter.cpp Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
abstractchapter.h Apply clang-format 2018-03-07 01:17:50 +01:00
abstractcontainer.cpp Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
abstractcontainer.h Refactor MediaFileInfo::createAppropriateTags() 2018-03-11 18:57:22 +01:00
abstracttrack.cpp Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
abstracttrack.h Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
aspectratio.cpp Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
aspectratio.h Apply clang-format 2018-03-07 01:17:50 +01:00
backuphelper.cpp Don't use global variable for backup directory 2018-07-12 12:34:38 +02:00
backuphelper.h Don't use global variable for backup directory 2018-07-12 12:34:38 +02:00
basicfileinfo.cpp Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
basicfileinfo.h Apply clang-format 2018-03-07 01:17:50 +01:00
caseinsensitivecomparer.h Apply clang-format 2018-03-07 01:17:50 +01:00
diagnostics.cpp Refactor formatting list of values 2018-07-01 22:11:34 +02:00
diagnostics.h Remove DiagPtr 2018-07-12 12:34:38 +02:00
exceptions.cpp Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
exceptions.h Apply clang-format 2018-03-07 01:17:50 +01:00
fieldbasedtag.h Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
genericcontainer.h Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
genericfileelement.h Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
generictagfield.h Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
global.h Apply clang-format later 2017-05-01 03:19:44 +02:00
localeawarestring.cpp Apply clang-format 2018-03-07 01:17:50 +01:00
localeawarestring.h Apply clang-format 2018-03-07 01:17:50 +01:00
margin.h Apply clang-format 2018-03-07 01:17:50 +01:00
mediafileinfo.cpp Implement small TODOs for v8 2018-07-12 12:34:38 +02:00
mediafileinfo.h Implement small TODOs for v8 2018-07-12 12:34:38 +02:00
mediaformat.cpp Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
mediaformat.h Use constexpr where possible 2018-07-12 12:34:38 +02:00
positioninset.h Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
progressfeedback.cpp Document progress feedback 2018-06-03 20:32:35 +02:00
progressfeedback.h Document progress feedback 2018-06-03 20:32:35 +02:00
settings.h Apply clang-format 2018-03-14 17:56:37 +01:00
signature.cpp Apply clang-format 2018-03-07 01:17:50 +01:00
signature.h Reorder enums 2018-03-21 20:31:29 +01:00
size.cpp Apply clang-format 2018-03-07 01:17:50 +01:00
size.h Apply clang-format 2018-03-07 01:17:50 +01:00
tag.cpp Use values.front() instead of *values.begin() 2018-07-12 12:34:16 +02:00
tag.h Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
tagtarget.cpp Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
tagtarget.h Apply clang-format 2018-03-07 01:17:50 +01:00
tagvalue.cpp Fix documentation which was still using the old namespace 2018-06-03 20:38:32 +02:00
tagvalue.h Implement small TODOs for v8 2018-07-12 12:34:38 +02: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>

using namespace TagParser;

// create a MediaFileInfo for high-level access to overall functionality of the library
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 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(KnownField::Title).toString(TagTextEncoding::Utf8);

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

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

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

Summary

  • So the most important class is 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 Failure.
  • All operations which might generate warnings, non-fatal errors, ... take a Diagnostics object to store those messages.
  • All operations which can be aborted or provide progress feedback take a AbortableProgressFeedback object for callbacks and aborting.
  • Field values are stored using TagValue objects. Those objects erase the actual type similar to QVariant from the Qt framework.

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

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. 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.