Tag Parser 12.4.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
|
Implementation of TagParser::AbstractTrack for the MP4 container. More...
#include <mp4track.h>
Public Member Functions | |
Mp4Track (Mp4Atom &trakAtom) | |
Constructs a new track for the specified trakAtom. | |
~Mp4Track () override | |
Destroys the track. | |
TrackType | type () const override |
Returns the type of the track if known; otherwise returns TrackType::Unspecified. | |
Mp4Atom & | trakAtom () |
Returns the trak atom for the current instance. | |
const std::vector< std::uint32_t > & | sampleSizes () const |
Returns the sample size table for the track. | |
unsigned int | chunkOffsetSize () const |
Returns the size of a single chunk offset denotation within the stco/co64 atom. | |
void | setChunkOffsetSize (unsigned int chunkOffsetSize) |
Sets the size of a single chunk offset denotation within the stco/co64 atom. | |
std::uint32_t | chunkCount () const |
Returns the number of chunks denoted by the stco/co64 atom. | |
std::uint32_t | sampleToChunkEntryCount () const |
Returns the number of "sample to chunk" entries within the stsc atom. | |
const Mpeg4ElementaryStreamInfo * | mpeg4ElementaryStreamInfo () const |
Returns information about the MPEG-4 elementary stream. | |
const AvcConfiguration * | avcConfiguration () const |
Returns the AVC configuration. | |
const Av1Configuration * | av1Configuration () const |
Returns the AV1 configuration. | |
std::vector< std::uint64_t > | readChunkOffsets (bool parseFragments, Diagnostics &diag) |
Reads the chunk offsets from the stco atom and fragments if parseFragments is true. | |
std::vector< std::tuple< std::uint32_t, std::uint32_t, std::uint32_t > > | readSampleToChunkTable (Diagnostics &diag) |
Reads the sample to chunk table. | |
std::vector< std::uint64_t > | readChunkSizes (TagParser::Diagnostics &diag) |
Reads the chunk sizes from the stsz (sample sizes) and stsc (samples per chunk) atom. | |
void | bufferTrackAtoms (Diagnostics &diag) |
Buffers all atoms required by the makeTrack() method. | |
std::uint64_t | chunkOffsetAtomSize (Diagnostics &diag) const |
Returns the size of the stco/co64 atom for this track based on the parsed/assigned chunkOffsetSize() and chunkCount(). | |
std::uint64_t | requiredSize (Diagnostics &diag) const |
Returns the number of bytes written when calling makeTrack(). | |
void | makeTrack (Diagnostics &diag) |
Makes the track entry ("trak"-atom) for the track. | |
void | makeTrackHeader (Diagnostics &diag) |
Makes the track header (tkhd atom) for the track. | |
void | makeMedia (Diagnostics &diag) |
Makes the media information (mdia atom) for the track. | |
void | makeMediaInfo (Diagnostics &diag) |
Makes a media information (minf atom) for the track. | |
void | makeSampleTable (Diagnostics &diag) |
Makes the sample table (stbl atom) for the track. | |
void | updateChunkOffsets (const std::vector< std::int64_t > &oldMdatOffsets, const std::vector< std::int64_t > &newMdatOffsets) |
Updates the chunk offsets of the track. | |
void | updateChunkOffsets (const std::vector< std::uint64_t > &chunkOffsets) |
Updates the chunk offsets of the track. | |
void | updateChunkOffset (std::uint32_t chunkIndex, std::uint64_t offset) |
Updates a particular chunk offset. | |
Public Member Functions inherited from TagParser::AbstractTrack | |
virtual | ~AbstractTrack () |
Destroys the track. | |
std::istream & | inputStream () |
Returns the associated input stream. | |
void | setInputStream (std::istream &stream) |
Assigns another input stream. | |
std::ostream & | outputStream () |
Returns the associated output stream. | |
void | setOutputStream (std::ostream &stream) |
Assigns another output stream. | |
CppUtilities::BinaryReader & | reader () |
Returns a binary reader for the associated stream. | |
CppUtilities::BinaryWriter & | writer () |
Returns a binary writer for the associated stream. | |
std::uint64_t | startOffset () const |
Returns the start offset of the track in the associated stream. | |
TrackFlags | flags () const |
Returns flags (various boolean properties) of this track. | |
MediaFormat | format () const |
Returns the format of the track if known; otherwise returns MediaFormat::Unknown. | |
double | version () const |
Returns the version/level of the track if known; otherwise returns 0. | |
std::string_view | formatName () const |
Returns the format of the track as C-style string if known; otherwise returns the format abbreviation or an empty string. | |
std::string_view | formatAbbreviation () const |
Returns the a more or less common abbreviation for the format of the track if known; otherwise returns an empty string. | |
const std::string & | formatId () const |
Returns the format/codec ID. | |
MediaType | mediaType () const |
Returns the media type if known; otherwise returns MediaType::Other. | |
std::string_view | mediaTypeName () const |
Returns the string representation of the media type of the track. | |
std::uint64_t | size () const |
Returns the size in bytes if known; otherwise returns 0. | |
void | setSize (std::uint64_t size) |
Sets the size in bytes. | |
std::uint32_t | trackNumber () const |
Returns the track number if known; otherwise returns 0. | |
void | setTrackNumber (std::uint32_t trackNumber) |
Sets the track number. | |
std::uint64_t | id () const |
Returns the track ID if known; otherwise returns 0. | |
void | setId (std::uint64_t id) |
Sets the track ID. | |
const std::string | name () const |
Returns the track name if known; otherwise returns an empty string. | |
void | setName (std::string_view name) |
Sets the name. | |
const CppUtilities::TimeSpan & | duration () const |
Returns the duration if known; otherwise returns a TimeSpan of zero ticks. | |
double | bitrate () const |
Returns the average bitrate in kbit/s if known; otherwise returns zero. | |
double | maxBitrate () const |
Returns the maximum bitrate in kbit/s if known; otherwise returns zero. | |
const CppUtilities::DateTime & | creationTime () const |
Returns the creation time if known; otherwise returns a DateTime of zero ticks. | |
const CppUtilities::DateTime & | modificationTime () const |
Returns the time of the last modification if known; otherwise returns a DateTime of zero ticks. | |
const Locale & | locale () const |
Returns the locale of the track if known; otherwise returns an empty locale. | |
void | setLocale (const Locale &locale) |
Sets the locale of the track. | |
std::uint32_t | samplingFrequency () const |
Returns the number of samples per second if known; otherwise returns 0. | |
std::uint32_t | extensionSamplingFrequency () const |
Returns the number of samples per second if known; otherwise returns 0. | |
std::uint16_t | bitsPerSample () const |
Returns the number of bits per sample; otherwise returns 0. | |
std::uint16_t | channelCount () const |
Returns the number of channels if known; otherwise returns 0. | |
std::uint8_t | channelConfig () const |
Returns the channel configuration. | |
std::string_view | channelConfigString () const |
Returns a string with the channel configuration if available; otherwise returns nullptr. | |
std::uint8_t | extensionChannelConfig () const |
Returns the extension channel configuration if available; otherwise returns nullptr. | |
std::string_view | extensionChannelConfigString () const |
Returns a string with the extension channel configuration if available; otherwise returns nullptr. | |
std::uint64_t | sampleCount () const |
Returns the number of samples/frames if known; otherwise returns 0. | |
int | quality () const |
Returns the quality if known; otherwise returns 0. | |
const Size & | pixelSize () const |
Returns the size of the encoded video frames if known; otherwise returns a zero size. | |
const Size & | displaySize () const |
Returns the size of the video frames to display if known; otherwise returns a zero size. | |
const Size & | resolution () const |
Returns the resolution if known; otherwise returns a zero size. | |
const std::string & | compressorName () const |
Returns the compressor name if known; otherwise returns an empty string. | |
void | setCompressorName (std::string_view compressorName) |
Returns the compressor name if known; otherwise returns an empty string. | |
std::uint16_t | depth () const |
Returns the bit depth if known; otherwise returns 0. | |
std::uint32_t | fps () const |
Returns the number of frames per second if known; otherwise returns 0. | |
std::string_view | chromaFormat () const |
Returns the chroma subsampling format if known; otherwise returns nullptr. | |
const AspectRatio & | pixelAspectRatio () const |
Returns the pixel aspect ratio (PAR). | |
bool | isInterlaced () const |
Returns true if the video is interlaced; otherwise returns false. | |
std::uint32_t | timeScale () const |
Returns the time scale if known; otherwise returns 0. | |
bool | isEnabled () const |
Returns true if the track is marked as enabled; otherwise returns false. | |
void | setEnabled (bool enabled) |
Sets whether the track is enabled. | |
bool | isDefault () const |
Returns true if the track is marked as default; otherwise returns false. | |
void | setDefault (bool isDefault) |
Sets whether the track is a default track. | |
bool | isForced () const |
Returns true if the track is marked as forced; otherwise returns false. | |
void | setForced (bool forced) |
Sets whether the track is forced. | |
bool | hasLacing () const |
Returns true if the track has lacing; otherwise returns false. | |
bool | isEncrypted () const |
Returns true if the track is marked as encrypted; otherwise returns false. | |
std::uint32_t | colorSpace () const |
Returns the color space if known; otherwise returns 0. | |
const Margin & | cropping () const |
Returns the cropping if known; otherwise returns zero margins. | |
std::string | label () const |
Returns a label for the track. | |
std::string | description () const |
Returns a description about the track. | |
std::string | shortDescription () const |
Returns a short description about the track. | |
void | parseHeader (Diagnostics &diag, AbortableProgressFeedback &progress) |
Parses technical information about the track from the header. | |
bool | isHeaderValid () const |
Returns an indication whether the track header is valid. | |
Static Public Member Functions | |
static std::unique_ptr< Mpeg4ElementaryStreamInfo > | parseMpeg4ElementaryStreamInfo (CppUtilities::BinaryReader &reader, Mp4Atom *esDescAtom, Diagnostics &diag) |
Reads the MPEG-4 elementary stream descriptor for the track. | |
static std::unique_ptr< Mpeg4AudioSpecificConfig > | parseAudioSpecificConfig (std::istream &stream, std::uint64_t startOffset, std::uint64_t size, Diagnostics &diag) |
Parses the audio specific configuration for the track. | |
static std::unique_ptr< Mpeg4VideoSpecificConfig > | parseVideoSpecificConfig (CppUtilities::BinaryReader &reader, std::uint64_t startOffset, std::uint64_t size, Diagnostics &diag) |
Parses the video specific configuration for the track. | |
static void | addInfo (const AvcConfiguration &avcConfig, AbstractTrack &track) |
Adds the information from the specified avcConfig to the specified track. | |
static void | addInfo (const Av1Configuration &av1Config, AbstractTrack &track) |
Adds the information from the specified av1Config to the specified track. | |
Protected Member Functions | |
void | internalParseHeader (Diagnostics &diag, AbortableProgressFeedback &progress) override |
This method is internally called to parse header information. | |
Protected Member Functions inherited from TagParser::AbstractTrack | |
AbstractTrack (std::istream &inputStream, std::ostream &outputStream, std::uint64_t startOffset) | |
Constructs a new track. | |
AbstractTrack (std::iostream &stream, std::uint64_t startOffset) | |
Constructs a new track. | |
Implementation of TagParser::AbstractTrack for the MP4 container.
TagParser::Mp4Track::Mp4Track | ( | Mp4Atom & | trakAtom | ) |
Constructs a new track for the specified trakAtom.
"trak"-atoms are stored in the top-level atom "move". Each "trak"-atom holds header information for one track in the MP4 file.
Note that the serializer functions of this class can only cope with "trak"-atoms that are within 32-bit limits. This should be ok because even for big files the header information should not grow that big. Even movenc.c
from libavformat only implements 32-bit size fields when writing "trak"-atoms.
Definition at line 153 of file mp4track.cpp.
|
override |
Destroys the track.
Definition at line 183 of file mp4track.cpp.
|
static |
Adds the information from the specified av1Config to the specified track.
Definition at line 1108 of file mp4track.cpp.
|
static |
Adds the information from the specified avcConfig to the specified track.
Definition at line 1074 of file mp4track.cpp.
|
inline |
Returns the AV1 configuration.
Definition at line 296 of file mp4track.h.
|
inline |
Returns the AVC configuration.
Definition at line 285 of file mp4track.h.
void TagParser::Mp4Track::bufferTrackAtoms | ( | Diagnostics & | diag | ) |
Buffers all atoms required by the makeTrack() method.
This allows to invoke makeTrack() also when the input stream is going to be modified (eg. to apply changed tags without rewriting the file).
Definition at line 1121 of file mp4track.cpp.
|
inline |
Returns the number of chunks denoted by the stco/co64 atom.
Definition at line 254 of file mp4track.h.
std::uint64_t TagParser::Mp4Track::chunkOffsetAtomSize | ( | Diagnostics & | diag | ) | const |
Returns the size of the stco/co64 atom for this track based on the parsed/assigned chunkOffsetSize() and chunkCount().
Definition at line 1152 of file mp4track.cpp.
|
inline |
Returns the size of a single chunk offset denotation within the stco/co64 atom.
Definition at line 237 of file mp4track.h.
|
overrideprotectedvirtual |
This method is internally called to parse header information.
It needs to be implemented when subclassing this class.
Throws | std::ios_base::failure when an IO error occurs. |
Throws | TagParser::Failure or a derived exception when a parsing error occurs. |
Implements TagParser::AbstractTrack.
Definition at line 1565 of file mp4track.cpp.
void TagParser::Mp4Track::makeMedia | ( | Diagnostics & | diag | ) |
Makes the media information (mdia atom) for the track.
The data is written to the assigned output stream at the current position.
Definition at line 1374 of file mp4track.cpp.
void TagParser::Mp4Track::makeMediaInfo | ( | Diagnostics & | diag | ) |
Makes a media information (minf atom) for the track.
The data is written to the assigned output stream at the current position.
Definition at line 1474 of file mp4track.cpp.
void TagParser::Mp4Track::makeSampleTable | ( | Diagnostics & | diag | ) |
Makes the sample table (stbl atom) for the track.
The data is written to the assigned output stream at the current position.
Definition at line 1517 of file mp4track.cpp.
void TagParser::Mp4Track::makeTrack | ( | Diagnostics & | diag | ) |
Makes the track entry ("trak"-atom) for the track.
The data is written to the assigned output stream at the current position. Note that this method uses the assigned input stream to copy some parts from the source file. Hence the input stream must still be valid when calling this method. To avoid this limitation call bufferTrackAtoms() before invalidating the input stream.
Definition at line 1257 of file mp4track.cpp.
void TagParser::Mp4Track::makeTrackHeader | ( | Diagnostics & | diag | ) |
Makes the track header (tkhd atom) for the track.
The data is written to the assigned output stream at the current position.
Definition at line 1286 of file mp4track.cpp.
|
inline |
Returns information about the MPEG-4 elementary stream.
Definition at line 274 of file mp4track.h.
|
static |
Parses the audio specific configuration for the track.
Definition at line 706 of file mp4track.cpp.
|
static |
Reads the MPEG-4 elementary stream descriptor for the track.
Definition at line 614 of file mp4track.cpp.
|
static |
Parses the video specific configuration for the track.
Definition at line 871 of file mp4track.cpp.
std::vector< std::uint64_t > TagParser::Mp4Track::readChunkOffsets | ( | bool | parseFragments, |
Diagnostics & | diag ) |
Reads the chunk offsets from the stco atom and fragments if parseFragments is true.
Throws | InvalidDataException when
|
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 202 of file mp4track.cpp.
vector< std::uint64_t > TagParser::Mp4Track::readChunkSizes | ( | TagParser::Diagnostics & | diag | ) |
Reads the chunk sizes from the stsz (sample sizes) and stsc (samples per chunk) atom.
Throws | InvalidDataException when
|
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 564 of file mp4track.cpp.
vector< tuple< std::uint32_t, std::uint32_t, std::uint32_t > > TagParser::Mp4Track::readSampleToChunkTable | ( | Diagnostics & | diag | ) |
Reads the sample to chunk table.
Definition at line 515 of file mp4track.cpp.
std::uint64_t TagParser::Mp4Track::requiredSize | ( | Diagnostics & | diag | ) | const |
Returns the number of bytes written when calling makeTrack().
Definition at line 1199 of file mp4track.cpp.
|
inline |
Returns the sample size table for the track.
Definition at line 224 of file mp4track.h.
|
inline |
Returns the number of "sample to chunk" entries within the stsc atom.
Definition at line 262 of file mp4track.h.
|
inline |
Sets the size of a single chunk offset denotation within the stco/co64 atom.
Definition at line 246 of file mp4track.h.
|
inline |
Returns the trak atom for the current instance.
Definition at line 212 of file mp4track.h.
|
overridevirtual |
Returns the type of the track if known; otherwise returns TrackType::Unspecified.
Reimplemented from TagParser::AbstractTrack.
Definition at line 187 of file mp4track.cpp.
void TagParser::Mp4Track::updateChunkOffset | ( | std::uint32_t | chunkIndex, |
std::uint64_t | offset ) |
Updates a particular chunk offset.
chunkIndex | Specifies the index of the chunk offset to be updated. |
offset | Specifies the new chunk offset. If the "stco" atom is used the value must fit into a 32-bit unsigned int. |
Throws | InvalidDataException when
|
Definition at line 1052 of file mp4track.cpp.
void TagParser::Mp4Track::updateChunkOffsets | ( | const std::vector< std::int64_t > & | oldMdatOffsets, |
const std::vector< std::int64_t > & | newMdatOffsets ) |
Updates the chunk offsets of the track.
This is necessary when the "mdat"-atom (which contains the actual chunk data) is moved.
oldMdatOffsets | Specifies a vector holding the old offsets of the "mdat"-atoms. |
newMdatOffsets | Specifies a vector holding the new offsets of the "mdat"-atoms. |
Throws | InvalidDataException when
|
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 947 of file mp4track.cpp.
void TagParser::Mp4Track::updateChunkOffsets | ( | const std::vector< std::uint64_t > & | chunkOffsets | ) |
Updates the chunk offsets of the track.
This is necessary when the "mdat"-atom (which contains the actual chunk data) is moved.
chunkOffsets | Specifies the new chunk offset table. If the "stco" atom is used the values must fit into an 32-bit unsigned int. |
Throws | InvalidDataException when
|
Definition at line 1014 of file mp4track.cpp.