Tag Parser  7.0.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
TagParser::Mp4Track Class Reference

#include <mp4track.h>

Inheritance diagram for TagParser::Mp4Track:
[legend]
Collaboration diagram for TagParser::Mp4Track:
[legend]

Public Member Functions

 Mp4Track (Mp4Atom &trakAtom)
 Constructs a new track for the specified trakAtom. More...
 
 ~Mp4Track () override
 Destroys the track. More...
 
TrackType type () const override
 Returns the type of the track if known; otherwise returns TrackType::Unspecified. More...
 
Mp4AtomtrakAtom ()
 Returns the trak atom for the current instance. More...
 
const std::vector< uint32 > & sampleSizes () const
 Returns the sample size table for the track. More...
 
unsigned int chunkOffsetSize () const
 Returns the size of a single chunk offset denotation within the stco atom. More...
 
uint32 chunkCount () const
 Returns the number of chunks denoted by the stco atom. More...
 
uint32 sampleToChunkEntryCount () const
 Returns the number of "sample to chunk" entries within the stsc atom. More...
 
const Mpeg4ElementaryStreamInfompeg4ElementaryStreamInfo () const
 Returns information about the MPEG-4 elementary stream. More...
 
const AvcConfigurationavcConfiguration () const
 Returns the AVC configuration. More...
 
std::vector< uint64 > readChunkOffsets (bool parseFragments, Diagnostics &diag)
 Reads the chunk offsets from the stco atom and fragments if parseFragments is true. More...
 
std::vector< std::tuple< uint32, uint32, uint32 > > readSampleToChunkTable (Diagnostics &diag)
 Reads the sample to chunk table. More...
 
std::vector< uint64 > readChunkSizes (TagParser::Diagnostics &diag)
 Reads the chunk sizes from the stsz (sample sizes) and stsc (samples per chunk) atom. More...
 
void bufferTrackAtoms (Diagnostics &diag)
 Buffers all atoms required by the makeTrack() method. More...
 
uint64 requiredSize (Diagnostics &diag) const
 Returns the number of bytes written when calling makeTrack(). More...
 
void makeTrack (Diagnostics &diag)
 Makes the track entry ("trak"-atom) for the track. More...
 
void makeTrackHeader (Diagnostics &diag)
 Makes the track header (tkhd atom) for the track. More...
 
void makeMedia (Diagnostics &diag)
 Makes the media information (mdia atom) for the track. More...
 
void makeMediaInfo (Diagnostics &diag)
 Makes a media information (minf atom) for the track. More...
 
void makeSampleTable (Diagnostics &diag)
 Makes the sample table (stbl atom) for the track. More...
 
void updateChunkOffsets (const std::vector< int64 > &oldMdatOffsets, const std::vector< int64 > &newMdatOffsets)
 Updates the chunk offsets of the track. More...
 
void updateChunkOffsets (const std::vector< uint64 > &chunkOffsets)
 Updates the chunk offsets of the track. More...
 
void updateChunkOffset (uint32 chunkIndex, uint64 offset)
 Updates a particular chunk offset. More...
 
- Public Member Functions inherited from TagParser::AbstractTrack
virtual ~AbstractTrack ()
 Destroys the track. More...
 
std::istream & inputStream ()
 Returns the associated input stream. More...
 
void setInputStream (std::istream &stream)
 Assigns another input stream. More...
 
std::ostream & outputStream ()
 Returns the associated output stream. More...
 
void setOutputStream (std::ostream &stream)
 Assigns another output stream. More...
 
IoUtilities::BinaryReader & reader ()
 Returns a binary reader for the associated stream. More...
 
IoUtilities::BinaryWriter & writer ()
 Returns a binary writer for the associated stream. More...
 
uint64 startOffset () const
 Returns the start offset of the track in the associated stream. More...
 
MediaFormat format () const
 Returns the format of the track if known; otherwise returns MediaFormat::Unknown. More...
 
double version () const
 Returns the version/level of the track if known; otherwise returns 0. More...
 
const char * formatName () const
 Returns the format of the track as C-style string if known; otherwise returns the format abbreviation or an empty string. More...
 
const char * formatAbbreviation () const
 Returns the a more or less common abbreviation for the format of the track as C-style string if known; otherwise returns an empty string. More...
 
const std::string & formatId () const
 Returns the format/codec ID. More...
 
MediaType mediaType () const
 Returns the media type if known; otherwise returns MediaType::Other. More...
 
const char * mediaTypeName () const
 Returns the string representation of the media type of the track. More...
 
uint64 size () const
 Returns the size in bytes if known; otherwise returns 0. More...
 
uint32 trackNumber () const
 Returns the track number if known; otherwise returns 0. More...
 
void setTrackNumber (uint32 trackNumber)
 Sets the track number. More...
 
uint64 id () const
 Returns the track ID if known; otherwise returns 0. More...
 
void setId (uint64 id)
 Sets the track ID. More...
 
const std::string name () const
 Returns the track name if known; otherwise returns an empty string. More...
 
void setName (const std::string &name)
 Sets the name. More...
 
const ChronoUtilities::TimeSpanduration () const
 Returns the duration if known; otherwise returns a TimeSpan of zero ticks. More...
 
double bitrate () const
 Returns the average bitrate in kbit/s if known; otherwise returns zero. More...
 
double maxBitrate () const
 Returns the maximum bitrate in kbit/s if known; otherwise returns zero. More...
 
const ChronoUtilities::DateTimecreationTime () const
 Returns the creation time if known; otherwise returns a DateTime of zero ticks. More...
 
const ChronoUtilities::DateTimemodificationTime () const
 Returns the time of the last modification if known; otherwise returns a DateTime of zero ticks. More...
 
const std::string & language () const
 Returns the language of the track if known; otherwise returns an empty string. More...
 
void setLanguage (const std::string &language)
 Sets the language of the track. More...
 
uint32 samplingFrequency () const
 Returns the number of samples per second if known; otherwise returns 0. More...
 
uint32 extensionSamplingFrequency () const
 Returns the number of samples per second if known; otherwise returns 0. More...
 
uint16 bitsPerSample () const
 Returns the number of bits per sample; otherwise returns 0. More...
 
uint16 channelCount () const
 Returns the number of channels if known; otherwise returns 0. More...
 
byte channelConfig () const
 Returns the channel configuration. More...
 
const char * channelConfigString () const
 Returns a string with the channel configuration if available; otherwise returns nullptr. More...
 
byte extensionChannelConfig () const
 Returns the extension channel configuration if available; otherwise returns nullptr. More...
 
const char * extensionChannelConfigString () const
 Returns a string with the extension channel configuration if available; otherwise returns nullptr. More...
 
uint64 sampleCount () const
 Returns the number of samples/frames if known; otherwise returns 0. More...
 
int quality () const
 Returns the quality if known; otherwise returns 0. More...
 
const SizepixelSize () const
 Returns the size of the encoded video frames if known; otherwise returns a zero size. More...
 
const SizedisplaySize () const
 Returns the size of the video frames to display if known; otherwise returns a zero size. More...
 
const Sizeresolution () const
 Returns the resolution if known; otherwise returns a zero size. More...
 
const std::string & compressorName () const
 Returns the compressor name if known; otherwise returns an empty string. More...
 
void setCompressorName (const std::string &compressorName)
 Returns the compressor name if known; otherwise returns an empty string. More...
 
uint16 depth () const
 Returns the bit depth if known; otherwise returns 0. More...
 
uint32 fps () const
 Returns the number of frames per second if known; otherwise returns 0. More...
 
const char * chromaFormat () const
 Returns the chroma subsampling format if known; otherwise returns nullptr. More...
 
const AspectRatiopixelAspectRatio () const
 Returns the pixel aspect ratio (PAR). More...
 
bool isInterlaced () const
 Returns true if the video is denoted as interlaced; otherwise returns false. More...
 
uint32 timeScale () const
 Returns the time scale if known; otherwise returns 0. More...
 
bool isEnabled () const
 Returns true if the track is denoted as enabled; otherwise returns false. More...
 
void setEnabled (bool enabled)
 Sets whether the track is enabled. More...
 
bool isDefault () const
 Returns true if the track is denoted as default; otherwise returns false. More...
 
void setDefault (bool isDefault)
 Sets whether the track is a default track. More...
 
bool isForced () const
 Returns true if the track is denoted as forced; otherwise returns false. More...
 
void setForced (bool forced)
 Sets whether the track is forced. More...
 
bool hasLacing () const
 Returns true if the track has lacing; otherwise returns false. More...
 
bool isEncrypted () const
 Returns true if the track is denoted as encrypted; otherwise returns false. More...
 
uint32 colorSpace () const
 Returns the color space if known; otherwise returns 0. More...
 
const Margincropping () const
 Returns the cropping if known; otherwise returns zero margins. More...
 
std::string label () const
 Returns a label for the track. More...
 
std::string description () const
 Returns a short description about the track. More...
 
void parseHeader (Diagnostics &diag)
 Parses technical information about the track from the header. More...
 
bool isHeaderValid () const
 Returns an indication whether the track header is valid. More...
 

Static Public Member Functions

static std::unique_ptr< Mpeg4ElementaryStreamInfoparseMpeg4ElementaryStreamInfo (IoUtilities::BinaryReader &reader, Mp4Atom *esDescAtom, Diagnostics &diag)
 Reads the MPEG-4 elementary stream descriptor for the track. More...
 
static std::unique_ptr< Mpeg4AudioSpecificConfigparseAudioSpecificConfig (std::istream &stream, uint64 startOffset, uint64 size, Diagnostics &diag)
 Parses the audio specific configuration for the track. More...
 
static std::unique_ptr< Mpeg4VideoSpecificConfigparseVideoSpecificConfig (IoUtilities::BinaryReader &reader, uint64 startOffset, uint64 size, Diagnostics &diag)
 Parses the video specific configuration for the track. More...
 
static void addInfo (const AvcConfiguration &avcConfig, AbstractTrack &track)
 Adds the information from the specified avcConfig to the specified track. More...
 

Protected Member Functions

void internalParseHeader (Diagnostics &diag) override
 This method is internally called to parse header information. More...
 
- Protected Member Functions inherited from TagParser::AbstractTrack
 AbstractTrack (std::istream &inputStream, std::ostream &outputStream, uint64 startOffset)
 Constructs a new track. More...
 
 AbstractTrack (std::iostream &stream, uint64 startOffset)
 Constructs a new track. More...
 

Additional Inherited Members

- Protected Attributes inherited from TagParser::AbstractTrack
std::istream * m_istream
 
std::ostream * m_ostream
 
IoUtilities::BinaryReader m_reader
 
IoUtilities::BinaryWriter m_writer
 
uint64 m_startOffset
 
bool m_headerValid
 
MediaFormat m_format
 
std::string m_formatId
 
std::string m_formatName
 
MediaType m_mediaType
 
double m_version
 
uint64 m_size
 
uint32 m_trackNumber
 
uint64 m_id
 
std::string m_name
 
ChronoUtilities::TimeSpan m_duration
 
double m_bitrate
 
double m_maxBitrate
 
ChronoUtilities::DateTime m_creationTime
 
ChronoUtilities::DateTime m_modificationTime
 
std::string m_language
 
uint32 m_samplingFrequency
 
uint32 m_extensionSamplingFrequency
 
uint16 m_bitsPerSample
 
uint32 m_bytesPerSecond
 
uint16 m_channelCount
 
byte m_channelConfig
 
byte m_extensionChannelConfig
 
uint16 m_chunkSize
 
uint64 m_sampleCount
 
int m_quality
 
Size m_pixelSize
 
Size m_displaySize
 
Size m_resolution
 
std::string m_compressorName
 
uint16 m_depth
 
uint32 m_fps
 
const char * m_chromaFormat
 
AspectRatio m_pixelAspectRatio
 
bool m_interlaced
 
uint32 m_timeScale
 
bool m_enabled
 
bool m_default
 
bool m_forced
 
bool m_lacing
 
bool m_encrypted
 
bool m_usedInPresentation
 
bool m_usedWhenPreviewing
 
uint32 m_colorSpace
 
Margin m_cropping
 

Detailed Description

Definition at line 117 of file mp4track.h.

Constructor & Destructor Documentation

◆ Mp4Track()

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.

Definition at line 130 of file mp4track.cpp.

◆ ~Mp4Track()

TagParser::Mp4Track::~Mp4Track ( )
override

Destroys the track.

Definition at line 156 of file mp4track.cpp.

Member Function Documentation

◆ addInfo()

void TagParser::Mp4Track::addInfo ( const AvcConfiguration avcConfig,
AbstractTrack track 
)
static

Adds the information from the specified avcConfig to the specified track.

Definition at line 1016 of file mp4track.cpp.

◆ avcConfiguration()

const AvcConfiguration * TagParser::Mp4Track::avcConfiguration ( ) const
inline

Returns the AVC configuration.

Remarks
  • The track must be parsed before this information becomes available.
  • The track keeps ownership over the returned object.

Definition at line 254 of file mp4track.h.

◆ bufferTrackAtoms()

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 1052 of file mp4track.cpp.

◆ chunkCount()

uint32 TagParser::Mp4Track::chunkCount ( ) const
inline

Returns the number of chunks denoted by the stco atom.

Definition at line 223 of file mp4track.h.

◆ chunkOffsetSize()

unsigned int TagParser::Mp4Track::chunkOffsetSize ( ) const
inline

Returns the size of a single chunk offset denotation within the stco atom.

Valid values are 4 and 8 bytes.

Definition at line 215 of file mp4track.h.

◆ internalParseHeader()

void TagParser::Mp4Track::internalParseHeader ( Diagnostics diag)
overrideprotectedvirtual

This method is internally called to parse header information.

It needs to be implemented when subclassing this class.

Exceptions
Throwsstd::ios_base::failure when an IO error occurs.
ThrowsMedia::Failure or a derived exception when a parsing error occurs.

Implements TagParser::AbstractTrack.

Definition at line 1439 of file mp4track.cpp.

◆ makeMedia()

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 1246 of file mp4track.cpp.

◆ makeMediaInfo()

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 1314 of file mp4track.cpp.

◆ makeSampleTable()

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.

Remarks
Not fully implemented yet.

Definition at line 1380 of file mp4track.cpp.

◆ makeTrack()

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 1142 of file mp4track.cpp.

◆ makeTrackHeader()

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 1168 of file mp4track.cpp.

◆ mpeg4ElementaryStreamInfo()

const Mpeg4ElementaryStreamInfo * TagParser::Mp4Track::mpeg4ElementaryStreamInfo ( ) const
inline

Returns information about the MPEG-4 elementary stream.

Remarks
  • The track must be parsed before this information becomes available.
  • The information is only available, if the track has an MPEG-4 elementary stream descriptor atom.
  • The track keeps ownership over the returned object.

Definition at line 243 of file mp4track.h.

◆ parseAudioSpecificConfig()

unique_ptr< Mpeg4AudioSpecificConfig > TagParser::Mp4Track::parseAudioSpecificConfig ( std::istream &  stream,
uint64  startOffset,
uint64  size,
Diagnostics diag 
)
static

Parses the audio specific configuration for the track.

Remarks
  • Notifications might be added.
See also
mpeg4ElementaryStreamInfo()

Definition at line 651 of file mp4track.cpp.

◆ parseMpeg4ElementaryStreamInfo()

std::unique_ptr< Mpeg4ElementaryStreamInfo > TagParser::Mp4Track::parseMpeg4ElementaryStreamInfo ( IoUtilities::BinaryReader &  reader,
Mp4Atom esDescAtom,
Diagnostics diag 
)
static

Reads the MPEG-4 elementary stream descriptor for the track.

Remarks
  • Notifications might be added.
See also
mpeg4ElementaryStreamInfo()

Definition at line 558 of file mp4track.cpp.

◆ parseVideoSpecificConfig()

std::unique_ptr< Mpeg4VideoSpecificConfig > TagParser::Mp4Track::parseVideoSpecificConfig ( IoUtilities::BinaryReader &  reader,
uint64  startOffset,
uint64  size,
Diagnostics diag 
)
static

Parses the video specific configuration for the track.

Remarks
  • Notifications might be added.
See also
mpeg4ElementaryStreamInfo()

Definition at line 818 of file mp4track.cpp.

◆ readChunkOffsets()

std::vector< uint64 > TagParser::Mp4Track::readChunkOffsets ( bool  parseFragments,
Diagnostics diag 
)

Reads the chunk offsets from the stco atom and fragments if parseFragments is true.

Returns
Returns the chunk offset table for the track.
Exceptions
ThrowsInvalidDataException when
  • there is no stream assigned.
  • the header has been considered as invalid when parsing the header information.
  • the determined chunk offset size is invalid.
Throwsstd::ios_base::failure when an IO error occurs.
See also
readChunkSizes();

Definition at line 175 of file mp4track.cpp.

◆ readChunkSizes()

vector< uint64 > TagParser::Mp4Track::readChunkSizes ( TagParser::Diagnostics diag)

Reads the chunk sizes from the stsz (sample sizes) and stsc (samples per chunk) atom.

Returns
Returns the chunk sizes for the track.
Exceptions
ThrowsInvalidDataException when
  • there is no stream assigned.
  • the header has been considered as invalid when parsing the header information.
  • the determined chunk offset size is invalid.
Throwsstd::ios_base::failure when an IO error occurs.
See also
readChunkOffsets();

Definition at line 506 of file mp4track.cpp.

◆ readSampleToChunkTable()

vector< tuple< uint32, uint32, uint32 > > TagParser::Mp4Track::readSampleToChunkTable ( Diagnostics diag)

Reads the sample to chunk table.

Returns
Returns a vector with the table entries wrapped using the tuple container. The first value is an integer that gives the first chunk that share the same samples count and sample description index. The second value is sample cound and the third value the sample description index.
Remarks
The table is not validated.

Definition at line 456 of file mp4track.cpp.

◆ requiredSize()

uint64 TagParser::Mp4Track::requiredSize ( Diagnostics diag) const

Returns the number of bytes written when calling makeTrack().

Definition at line 1088 of file mp4track.cpp.

◆ sampleSizes()

const std::vector< uint32 > & TagParser::Mp4Track::sampleSizes ( ) const
inline

Returns the sample size table for the track.

Remarks
If the table contains only one size this is the constant sample size.
The table is empty if the track denotes 64-bit sample sizes.
See also
sampleSizes64()

Definition at line 205 of file mp4track.h.

◆ sampleToChunkEntryCount()

uint32 TagParser::Mp4Track::sampleToChunkEntryCount ( ) const
inline

Returns the number of "sample to chunk" entries within the stsc atom.

Definition at line 231 of file mp4track.h.

◆ trakAtom()

Mp4Atom & TagParser::Mp4Track::trakAtom ( )
inline

Returns the trak atom for the current instance.

Definition at line 193 of file mp4track.h.

◆ type()

TrackType TagParser::Mp4Track::type ( ) const
overridevirtual

Returns the type of the track if known; otherwise returns TrackType::Unspecified.

Reimplemented from TagParser::AbstractTrack.

Definition at line 160 of file mp4track.cpp.

◆ updateChunkOffset()

void TagParser::Mp4Track::updateChunkOffset ( uint32  chunkIndex,
uint64  offset 
)

Updates a particular chunk offset.

Parameters
chunkIndexSpecifies the index of the chunk offset to be updated.
offsetSpecifies the new chunk offset.
Remarks
This method seems to be obsolete.
Exceptions
ThrowsInvalidDataException when
  • there is no stream assigned.
  • the header has been considered as invalid when parsing the header information.
  • chunkIndex is not less than chunkCount().
  • there is no atom holding these offsets.
  • the ID of the atom holding these offsets is not "stco" or "co64".

Definition at line 995 of file mp4track.cpp.

◆ updateChunkOffsets() [1/2]

void TagParser::Mp4Track::updateChunkOffsets ( const std::vector< int64 > &  oldMdatOffsets,
const std::vector< int64 > &  newMdatOffsets 
)

Updates the chunk offsets of the track.

This is necessary when the "mdat"-atom (which contains the actual chunk data) is moved.

Parameters
oldMdatOffsetsSpecifies a vector holding the old offsets of the "mdat"-atoms.
newMdatOffsetsSpecifies a vector holding the new offsets of the "mdat"-atoms.
Exceptions
ThrowsInvalidDataException when
  • there is no stream assigned.
  • the header has been considered as invalid when parsing the header information.
  • oldMdatOffsets holds not the same number of offsets as newMdatOffsets.
  • there is no atom holding these offsets.
  • the ID of the atom holding these offsets is not "stco" or "co64"
Throwsstd::ios_base::failure when an IO error occurs.
Remarks
This method needs to be fixed.

Definition at line 893 of file mp4track.cpp.

◆ updateChunkOffsets() [2/2]

void TagParser::Mp4Track::updateChunkOffsets ( const std::vector< uint64 > &  chunkOffsets)

Updates the chunk offsets of the track.

This is necessary when the "mdat"-atom (which contains the actual chunk data) is moved.

Parameters
chunkOffsetsSpecifies the new chunk offset table.
Exceptions
ThrowsInvalidDataException when
  • there is no stream assigned.
  • the header has been considered as invalid when parsing the header information.
  • the size of chunkOffsets does not match chunkCount().
  • there is no atom holding these offsets.
  • the ID of the atom holding these offsets is not "stco" or "co64".

Definition at line 959 of file mp4track.cpp.


The documentation for this class was generated from the following files: