Instance Property

formatDescriptions

The format descriptions of the media samples referenced by the track.

Declaration

@property(nonatomic, readonly) NSArray *formatDescriptions;

Discussion

The array contains CMFormatDescriptions (see CMFormatDescriptionRef), each of which indicates the format of media samples referenced by the track.

Asset tracks commonly present uniform media (for example, encoded according to the same encoding settings) and will contain a single format description. However, there are cases where an asset track may contain multiple format descriptions. For instance, an H.264-encoded video track may have some of its segments encoded using the Main profile and others using the High profile. Additionally, an individual AVCompositionTrack, which is a subclass of AVAssetTrack, may contain audio or video segments using different codecs (aac, mp3, aiff, etc.).

You can use the CMFormatDescriptionRef to access low-level details about the media referenced by the track. For instance, you could retrieve the details of track’s media type and subtype as follows:

@implementation AVAssetTrack (CoreMediaExtensions)
 
- (NSString *)mediaFormat {
    NSMutableString *format = [[NSMutableString alloc] init];
    for (int i = 0; i < self.formatDescriptions.count; i++) {
        CMFormatDescriptionRef desc =
            (__bridge CMFormatDescriptionRef)self.formatDescriptions[i];
        // Get String representation of media type (vide, soun, sbtl, etc.)
        NSString *type = FourCCString(CMFormatDescriptionGetMediaType(desc));
        // Get String representation media subtype (avc1, aac, tx3g, etc.)
        NSString *subType = FourCCString(CMFormatDescriptionGetMediaSubType(desc));
        // Format string as type/subType
        [format appendFormat:@"%@/%@", type, subType];
        // Comma separate if more than one format description
        if (i < self.formatDescriptions.count - 1) {
            [format appendString:@","];
        }
    }
    return format;
}
 
static NSString * FourCCString(FourCharCode code) {
    NSString *result = [NSString stringWithFormat:@"%c%c%c%c",
                        (code >> 24) & 0xff,
                        (code >> 16) & 0xff,
                        (code >> 8) & 0xff,
                        code & 0xff];
    NSCharacterSet *characterSet = [NSCharacterSet whitespaceCharacterSet];
    return [result stringByTrimmingCharactersInSet:characterSet];
}
 
@end

See Also

Retrieving Track Information

asset

The asset of which the track is a part.

trackID

The persistent unique identifier for this track.

mediaType

The media type for the track.

- hasMediaCharacteristic:

Returns a Boolean value that indicates whether the track references media with the specified media characteristic.

AVMediaCharacteristic

The options for specifying media type characteristics.

enabled

A Boolean value that indicates whether the track is enabled according to the state stored in its container.

playable

A Boolean value that indicates whether the track is playable in the current environment.

selfContained

A Boolean value that indicates whether the track references sample data contained only within its storage container.

estimatedDataRate

The estimated data rate, in bits per second, of the media data referenced by the track.

totalSampleDataLength

The total number of bytes of sample data required by the track.

decodable

A Boolean value that indicates whether the receiver is decodable in the current environment.