TweetFollow Us on Twitter

The Informer

Volume Number: 21 (2005)
Issue Number: 10
Column Tag: Programming

QuickTime Toolkit

The Informer: Using the QuickTime Metadata Functions

by Tim Monroe

QuickTime has from its very beginnings provided a way for movie creators and editors to add descriptive information to a movie or its tracks. For instance, the movie creator may want to attach a copyright notification or a brief comment to the movie. Typically this kind of information is called metadata, since it's information about the movie (or track or media). Sometimes, especially if it's text data, this information is also called an annotation. For reasons that will become clear in a moment, it's useful to adopt a more general term; so let's use the term metainformation to talk about this sort of additional data that describes a movie (or track or media).

Introduction

Originally, metainformation was added to a movie file by adding user data items to a user data list associated with the movie, one of its tracks, or the media associated with one of those tracks. We spent parts of several earlier articles ("Movie Controller Potpourri" in MacTech, February 2000 and "The Informant" in MacTech, August 2000) investigating the user data functions provided by QuickTime. We saw how to read and write user data items to manage the movie's controller type, window position, looping state, and annotations.

The user data method of managing metainformation is subject to several important limitations. First, as we saw in those articles, a particular user data item is specified only by a four-character code -- for instance, '(c)cpy' for the copyright notification -- and an index. Lacking a complete list of all in-use codes, it's difficult for third-party developers to define their own custom user data types without fear of colliding with those of other developers. Also, a developer wanting to work with known user data types also has to know the structure of the data contained in the item. Nothing about the user data item or its four-character code reveals the type of data that will be returned by a call to GetUserDataItem. (Although in general the "(c)" character at the beginning of a user data type indicates that the data is text, nothing inside of QuickTime enforces that rule.) Finally, user data is always stored inside of the movie atom in a QuickTime file, which might not be the ideal location for some large collections of metainformation.

QuickTime 7 introduced a new set of functions -- called QuickTime metadata functions -- that are intended to address these (and other) shortcomings of the user data method of storing metainformation. These metadata functions allow developers to access metainformation stored in a variety of formats, including classic user data items, iTunes tags, and a new format called QuickTime metadata. In this article, I want to take a look at these new functions. We'll see how to use them to read and write metainformation in any of the supported formats. Along the way, we'll see how to do some fun stuff like read the album artwork out of an iTunes music file.

QuickTime Metadata Architecture

QuickTime 7 incorporates two important enhancements in its support for reading and writing metainformation in a QuickTime movie. First, it defines a new metainformation storage format called the QuickTime metadata format. The main interesting thing about this new storage format is that it uses item specifications in a reverse-DNS form, such as com.apple.quicktime.copyright and com.apple.quicktime.author. This type of specification is far more readable than the four-character codes used with user data, and it more easily prevents namespace collisions.

The more important enhancement is the QuickTime metadata architecture, which provides a set of QuickTime metadata functions that we can use to read and write metainformation in any supported storage format. That is to say, we can use these functions to access user data, QuickTime metadata, and iTunes metadata tags. And this architecture is inherently extensible, so support for other storage formats could be added in the future.

To understand this new architecture, let's begin by reviewing the simpler user data architecture. A user data item is stored in a user data list, with one list per movie, track, or media. As noted above, it's possible to have several user data items of the same type in a single user data list. The only flexibility available in this scheme is that text-related items also have a region code, which specifies a version of a written language of a particular region in the world. (And even this flexibility is of limited usefulness: the text-related user data APIs such as GetUserDataText and AddUserDataText assume that the text string is in one of the traditional Mac OS language encodings, such as kTextEncodingMacRoman or kTextEncodingMacJapanese. Strings in Unicode or mixed encodings are not easily supported.)

In the new QuickTime metadata architecture, metadata is accessed using a metadata reference (an opaque identifier of type QTMetaDataRef). There is one metadata reference per movie, track, or media. A single metadata reference can pick out one or more metadata containers, which are distinguished from one another by their storage format. Currently the metadata APIs recognize these three storage formats:

enum {
   kQTMetaDataStorageFormatQuickTime      = 'mdta',
   kQTMetaDataStorageFormatiTunes         = 'itms',
   kQTMetaDataStorageFormatUserData       = 'udta'
};

As you might guess, these correspond to the new QuickTime metadata format, the iTunes metadata format, and the user data format.

A metadata container holds one or more metadata items. Each metadata item is accessed by a metadata item reference (an opaque identifier of type QTMetaDataItem). A given metadata item has a number of attributes, including its data type, its locale, and its key. The key is analogous to the user data type considered above, insofar as it is a label for the sort of data contained in the metadata item. Indeed, when the storage format is kQTMetaDataStorageFormatUserData, the metadata item key is a four-character code that indicates the user data type. The format of the key for a specific metadata item depends on the storage format of that item. Here are the currently defined key formats:

enum {
   kQTMetaDataKeyFormatQuickTime             = 'mdta',
   kQTMetaDataKeyFormatiTunesShortForm       = 'itsk',
   kQTMetaDataKeyFormatiTunesLongForm        = 'itlk', 
   kQTMetaDataKeyFormatUserData              = 'udta'
};

Both of the key format constants kQTMetaDataKeyFormatiTunesShortForm and kQTMetaDataKeyFormatUserData indicate a four-character code format, like '(c)aut' or '(c)nam'. And both of the key format constants kQTMetaDataKeyFormatQuickTime and kQTMetaDataKeyFormatiTunesLongForm indicate the reverse DNS format mentioned above (for example, com.apple.quicktime.author).

So, we've seen that a metadata container has one of the three recognized storage formats (iTunes, user data, or QuickTime metadata), and each storage format supports one or more key formats. In some of the functions that require a storage format or key format as a parameter, we can also specify these wildcard values:

enum {
   kQTMetaDataStorageFormatWildcard       = 0,
   kQTMetaDataKeyFormatWildcard           = 0
};

As we'll soon see, these wildcards are especially useful when we want to iterate over all the metadata items in a metadata container or all the containers in a metadata reference.

There is one final element to working with keys. We've just seen that the author data, for instance, may be accessed using the key '(c)aut' in one metadata container and by the key com.apple.quicktime.author in another. QuickTime supports a set of common keys that can be used to access metadata items in any kind of storage container, regardless of its native key format. Here are the currently defined common keys:

enum {
  kQTMetaDataCommonKeyAuthor              = 'auth',
  kQTMetaDataCommonKeyComment             = 'cmmt',
  kQTMetaDataCommonKeyCopyright           = 'cprt',
  kQTMetaDataCommonKeyDirector            = 'dtor',
  kQTMetaDataCommonKeyDisplayName         = 'name',
  kQTMetaDataCommonKeyInformation         = 'info',
  kQTMetaDataCommonKeyKeywords            = 'keyw',
  kQTMetaDataCommonKeyProducer            = 'prod',
  kQTMetaDataCommonKeyAlbum               = 'albm',
  kQTMetaDataCommonKeyArtist              = 'arts',
  kQTMetaDataCommonKeyArtwork             = 'artw',
  kQTMetaDataCommonKeyChapterName         = 'chap',
  kQTMetaDataCommonKeyComposer            = 'comp',
  kQTMetaDataCommonKeyDescription         = 'desc',
  kQTMetaDataCommonKeyGenre               = 'genr',
  kQTMetaDataCommonKeyOriginalFormat      = 'orif',
  kQTMetaDataCommonKeyOriginalSource      = 'oris',
  kQTMetaDataCommonKeyPerformers          = 'perf',
  kQTMetaDataCommonKeySoftware            = 'soft',
  kQTMetaDataCommonKeyWriter              = 'wrtr'
};

When we want to use one of these common keys, we need to use this key format:

enum {
   kQTMetaDataKeyFormatCommon             = 'comn'
};

QuickTime Metadata Functions

Let's stop kicking the tires and take the new metadata functions for a spin. In particular, let's see how to get a metadata reference, find specific metadata items, and perform various operations on those items.

Getting a Metadata Reference

Recall that each movie, track, and media in a movie has an associated metadata reference. We can get those references by calling QTCopyMovieMetaData, QTCopyTrackMetaData, and QTCopyMediaMetaData. In this article we'll be working exclusively with the movie metadata, so we can retrieve the metadata reference like this:

QTMetaDataRef metaDataRef = NULL;
QTCopyMovieMetaData(movie, &metaDataRef);

The QTCopyMovieMetaData function returns the metadata reference associated with the specified movie. The "Copy" part of the function name indicates that the function has a reference-counted semantics like many Core Foundation functions that have "Copy" in their name. That is to say, when the QTCopyMovieMetaData function returns, the metadata reference has already been retained. That reference is valid at least until the matching call to the QTMetaDataRelease function, which decrements the reference count and deallocates the object when the reference count falls to 0:

QTMetaDataRelease(metaDataRef);

QuickTime also provides the QTMetaDataRetain function for manually incrementing the reference count of a metadata reference. Each call to QTMetaDataRetain should be matched by a call to QTMetaDataRelease.

Adding Metadata Items

It's very easy to add new metadata items to a storage container using the QTMetaDataAddItem function. These lines of code show how to add an author annotation in QuickTime metadata format:

char key[] = "com.apple.quicktime.author";
char val[] = "Andy Warhol";

QTMetaDataAddItem(metaDataRef, 
      kQTMetaDataStorageFormatQuickTime, 
      kQTMetaDataKeyFormatQuickTime, 
      key, sizeof(key), val, sizeof(val), 
      kQTMetaDataTypeUTF8, &item);

This code adds a new author metadata item whose value is set to "Andy Warhol"; if successful, QTMetaDataAddItem returns the new metadata item identifier in the last parameter. The penultimate parameter indicates the data type of the item's data. The following constants are defined in the header file Movies.h:

enum {
  kQTMetaDataTypeBinary                = 0,
  kQTMetaDataTypeUTF8                  = 1,
  kQTMetaDataTypeUTF16BE               = 2,
  kQTMetaDataTypeMacEncodedText        = 3,
  kQTMetaDataTypeSignedIntegerBE       = 21,
  kQTMetaDataTypeUnsignedIntegerBE     = 22,
  kQTMetaDataTypeFloat32BE             = 23,
  kQTMetaDataTypeFloat64BE             = 24
};

As you can see, we've specified kQTMetaDataTypeUTF8 for ASCII text.

Getting and Setting Metadata Item Properties

Once we've got a metadata item (either by adding one to a metadata container, or by searching for one, as described below), we can get and set its properties by calling the QTMetaDataGetItemProperty and QTMetaDataSetItemProperty functions. For instance, the call we just made to QTMetaDataAddItem does not set the locale of the metadata item. We can do that quite easily like this:

char loc[] = "en";
QTMetaDataSetItemProperty(metaDataRef, item, 
      kPropertyClass_MetaDataItem, 
      kQTMetaDataItemPropertyID_Locale, sizeof(loc), loc);

A particular property is identified by its property class and its property ID. The property class indicates the kind of object whose information we want to get or set. Currently we can get or set information on a metadata reference or a metadata item:

enum {
   kPropertyClass_MetaData         = 'meta'
   kPropertyClass_MetaDataItem     = 'mdit'
 };

The property ID indicates which property of the specified object we want to query; here are the recognized IDs for metadata item properties:

enum {
   kQTMetaDataItemPropertyID_Value           = 'valu',
   kQTMetaDataItemPropertyID_DataType        = 'dtyp',
   kQTMetaDataItemPropertyID_StorageFormat   = 'sfmt',
   kQTMetaDataItemPropertyID_Key             = 'key',                    	
   kQTMetaDataItemPropertyID_KeyFormat       = 'keyf',
   kQTMetaDataItemPropertyID_Locale          = 'loc '
};

When we want to get the value of a metadata item property, we first need to determine the size of the requested data, so we know how big to make the buffer to receive the data. We can do this by calling QTMetaDataGetItemPropertyInfo. For instance, suppose we want to determine the data type of the data in a given metadata item. First we do this:

ByteCount size = 0;
err = QTMetaDataGetItemPropertyInfo(metaDataRef, item, 
            kPropertyClass_MetaDataItem, 
            kQTMetaDataItemPropertyID_DataType, 
            NULL, &size, NULL);

At this point, the size variable should contain the size, in bytes, of the data type. We can then retrieve that data type like this:

QTPropertyValuePtr outValPtr = malloc(size);

err = QTMetaDataGetItemProperty(metaDataRef, item, 
            kPropertyClass_MetaDataItem, 
            kQTMetaDataItemPropertyID_DataType, 
            size, outValPtr, NULL);

Finding Metadata Items

Once we've got a metadata reference, we can operate on the metadata containers associated with it, as well as the metadata items in those containers. To find specific metadata items, we can call the QTMetaDataGetNextItem function, which is declared like this:

OSStatus QTMetaDataGetNextItem (
  QTMetaDataRef               inMetaData,
  QTMetaDataStorageFormat     inMetaDataFormat,
  QTMetaDataItem              inCurrentItem,
  QTMetaDataKeyFormat         inKeyFormat,
  const UInt8 *               inKeyPtr,
  ByteCount                   inKeySize,
  QTMetaDataItem *            outNextItem);

The inMetaData parameter is the metadata reference. The inMetaDataFormat parameter indicates the desired storage format, and the inKeyFormat indicates the desired key format. The inKeyPtr and inKeySize parameters indicate the actual metadata item key and the size of that key.

The only mildly tricky parameter is inCurrentItem; it is used to indicate the item we are currently inspecting, so that the call to QTMetaDataGetNextItem will retrieve the next item. When we first call QTMetaDataGetNextItem, we will want to set the inCurrentItem parameter to kQTMetaDataItemUninitialized, to indicate that we haven't retrieved any items yet.

Suppose that we want to find the copyright user data items in a QuickTime movie. We could call QTMetaDataGetNextItem like this:

OSType key = kUserDataTextCopyright;
err = QTMetaDataGetNextItem(metaDataRef,
            kQTMetaDataStorageFormatUserData,
            kQTMetaDataItemUninitialized, 
            kQTMetaDataKeyFormatUserData,
            &key, sizeof(key), &item);

A metadata item reference for the first such user data item will be returned in the final parameter. If there is more than one, then subsequent calls to this line of code will retrieve the remaining items:

err = QTMetaDataGetNextItem(metaDataRef,
            kQTMetaDataStorageFormatUserData,
            item, 
            kQTMetaDataKeyFormatUserData,
            &key, sizeof(key), &item);

Similarly, we can get the first QuickTime metadata copyright item like this:

UInt8 key[] = "com.apple.quicktime.copyright";
err = QTMetaDataGetNextItem(metaDataRef,
            kQTMetaDataStorageFormatQuickTime,
            kQTMetaDataItemUninitialized, 
            kQTMetaDataKeyFormatQuickTime,
            &key, sizeof(key), &item);

Iterating through Metadata Items

If we want to inspect each and every movie metadata item, we could iterate through them using a while loop, like this:

item = kQTMetaDataItemUninitialized;
while (QTMetaDataGetNextItem(metaDataRef, 
            kQTMetaDataStorageFormatWildcard, item,
            kQTMetaDataKeyFormatWildcard,
            NULL, 0, &item) == noErr) {
      // do something useful here, like read the properties of the item
}

Listing 1 shows a real-world example of iterating through metadata items. In this case, we are removing all metadata items in a metadata reference.

Listing 1: Removing all metadata items

- (void)removeMetaData
{
   Movie movie = [_movie quickTimeMovie];
   QTMetaDataRef metaDataRef = NULL;
   QTMetaDataItem item = kQTMetaDataItemUninitialized;
   OSStatus err = noErr;

   // get the metadata reference
   err = QTCopyMovieMetaData(movie, &metaDataRef);
   if (err)
      goto bail;

   // remove all metadata items
   while (QTMetaDataGetNextItem(metaDataRef, 
               kQTMetaDataStorageFormatWildcard, 0,
               kQTMetaDataKeyFormatWildcard,
               NULL, 0, &item) == noErr) {
      QTMetaDataRemoveItem(metaDataRef, item);
   }

   [_movie updateMovieFile];

bail:
   // release the metadata reference
   if (metaDataRef)
      QTMetaDataRelease(metaDataRef);
}

Notice that when removing items, we do not pass the current item in the third parameter, since it will be invalid once we remove it. Passing 0 in that parameter will always give us the first item remaining in the list.

Album Artwork

We have seen that the new QuickTime metadata functions allow us to work with iTunes metadata as well as with classic user data and the new QuickTime metadata. And you probably know that many iTunes songs contain album artwork, as shown in Figure 1.


Figure 1: Album artwork displayed by iTunes

Currently, our sample applications open an audio-only movie in a window with no visual content, as in Figure 2.


Figure 2: A movie window for audio-only files

It would be nice to be able to extract and display this album art when our applications open an iTunes song. So the movie window would now look like Figure 3.


Figure 3: A movie window with album artwork

In this section, we'll see how to do that. Extracting album artwork from an iTunes file is indeed supported by the public QuickTime metadata APIs, but a few important details are not currently documented. So we'll need to do a small bit of sleuthing to fill in the gaps.

Retrieving the Album Artwork

It's reasonably straightforward to retrieve the album artwork data from an iTunes song. You may have noticed the kQTMetaDataCommonKeyArtwork key listed above. All we need to do is search all available data storage formats for the kQTMetaDataCommonKeyArtwork key, like this:

OSType metaDataKey = kQTMetaDataCommonKeyArtwork;
QTMetaDataItem item = kQTMetaDataItemUninitialized;

QTCopyMovieMetaData(movie, &metaDataRef);
QTMetaDataGetNextItem(metaDataRef,
kQTMetaDataStorageFormatWildcard, 0, 
   kQTMetaDataKeyFormatCommon, (const UInt8 *)&metaDataKey, 
   sizeof(metaDataKey), &item);

If any available storage format contains an album artwork data item, then upon successful completion of these lines of code, item will contain an identifier for that item.

Next we need to determine the size of the album artwork data and allocate a buffer large enough to hold it. We can do that like this:

ByteCount size;
char *data = NULL:
	
QTMetaDataGetItemValue(metaDataRef, item, NULL, 0, &size);
data = malloc(size);

Finally, we can retrieve the album artwork data by calling QTMetaDataGetItemValue, like this:

QTMetaDataGetItemValue(metaDataRef, item, data, size, 
   NULL);

So far, so good. But before we can do anything with this block of album artwork data, we need to figure out the format of the data. This is easy enough, using the QTMetaDataGetItemProperty function:

QTPropertyValueType dataType;

QTMetaDataGetItemProperty(metaDataRef, item, 
   kPropertyClass_MetaDataItem, 
   kQTMetaDataItemPropertyID_DataType, 
   sizeof(dataType), &dataType, NULL);

When we execute this code for the album artwork data shown above, we determine that the dataType variable is set to 14.

Here is where the header files and public documentation become less helpful. The value 14 is not among the public data type codes listed earlier, but it's not too difficult to determine what sort of data it picks out. If we look at the bytes in the block of data, we'll see that the first four bytes are 0x89504e47, which in ASCII format is "aPNG". So it's a reasonable guess that a data type of 14 indicates that the image is a PNG image. Likewise, the first four bytes of the artwork data contained in some other file might be 0xffd8ffe0, which indicates a JPEG image. Similar sleuthing will reveal that a data type of 12 indicates a GIF image and that 27 indicates a BMP image. We can encapsulate our findings in these private constants:

enum {
   kMyQTMetaDataTypeGIF                   = 12,
   kMyQTMetaDataTypeJPEG                  = 13,
   kMyQTMetaDataTypePNG                   = 14,
   kMyQTMetaDataTypeBMP                   = 27
};

Creating an Album Artwork Movie

So, we have retrieved a block of data that contains an album artwork image, and we have made some reasonable guesses about the format of the data. How do we display that image as a video track in the audio-only QuickTime movie that we have opened? If we are working in Cocoa, we can use the method illustrated in a recent article ("Back to the Future, Part III" in MacTech, July 2005) which invokes the QTMovie method dataReferenceWithReferenceToData:name:MIMEType:; this method creates a data reference to some block of memory addressed using an NSData object and optionally attaches a filenaming extension or a data reference extension of type 'mime' to the data reference. In the present case, we want to attach a filenaming extension to the data reference, as shown in Listing 2.

Listing 2: Creating a movie from a single image

QTMovie *artworkMovie = nil;
NSString *pathExtension = nil;
						
switch (artworkDataType) {
   case kMyQTMetaDataTypeGIF:
      pathExtension = @"gif";    break;
   case kMyQTMetaDataTypeJPEG:
      pathExtension = @"jpg";    break;
   case kMyQTMetaDataTypePNG:
      pathExtension = @"png";    break;
   case kMyQTMetaDataTypeBMP:
      pathExtension = @"bmp";    break;
}

if (pathExtension) {
   NSString *name = [NSString stringWithFormat:
            @"artworkImage.%@", pathExtension];
   QTDataReference *dataReference = [QTDataReference 
            dataReferenceWithReferenceToData:artworkItemData 
            name:name MIMEType:nil];
							
   artworkMovie = [QTMovie movieWithDataReference:
            dataReference error:nil];
}

On successful completion of this code, the artworkMovie variable contains a QTMovie object with a single video track whose only frame is the artwork metadata image. (If you are not using Cocoa and hence cannot rely on the QTKit methods used here, you can instead use the standard Carbon APIs as illustrated in "Somewhere I'll Find You" in MacTech, October 2000.)

Listing 3 shows the complete version of the albumArtworkMovie method.

Listing 3: Retrieving the album artwork

- (QTMovie *)albumArtworkMovie
{
   QTMovie *artworkMovie = nil;
   QTMetaDataRef metaDataRef = NULL;
   OSErr err = noErr;

   err = QTCopyMovieMetaData([[movieView movie] 
               quickTimeMovie], &metaDataRef);
   if (err == noErr) {
      OSType metaDataKey = kQTMetaDataCommonKeyArtwork;
      QTMetaDataItem item = kQTMetaDataItemUninitialized;

      err = QTMetaDataGetNextItem(metaDataRef, 
                  kQTMetaDataStorageFormatWildcard, 0, 
                  kQTMetaDataKeyFormatCommon, 
                  (const UInt8 *)&metaDataKey, 
                  sizeof(metaDataKey), &item);
      if (err == noErr) {
         ByteCount artworkSize;

         err = QTMetaDataGetItemValue(metaDataRef, item, NULL, 
                     0, &artworkSize);
         if (err == noErr) {
            NSMutableData *artworkItemData = [NSMutableData 
                     dataWithLength:artworkSize];

            err = QTMetaDataGetItemValue(metaDataRef, item, 
                        [artworkItemData mutableBytes], 
                        artworkSize, NULL);
            if (err == noErr) {
               OSType artworkDataType;

               err = QTMetaDataGetItemProperty(metaDataRef, 
                           item, kPropertyClass_MetaDataItem, 
                           kQTMetaDataItemPropertyID_DataType, 
                           sizeof(artworkDataType), 
                           &artworkDataType, NULL);
               if (err == noErr) {
                  NSString *pathExtension = nil;

                  switch (artworkDataType) {
                     case kMyQTMetaDataTypeGIF:
                        pathExtension = @"gif";    break;
                     case kMyQTMetaDataTypeJPEG:
                        pathExtension = @"jpg";    break;
                     case kMyQTMetaDataTypePNG:
                        pathExtension = @"png";    break;
                     case kMyQTMetaDataTypeBMP:
                        pathExtension = @"bmp";    break;
                  }
						
                  if (pathExtension) {
                     NSString *name = [NSString 
                              stringWithFormat:@"artworkImage.%@", 
                              pathExtension];
                     QTDataReference *dataReference = 
                              [QTDataReference 
                                 dataReferenceWithReferenceToData:
                                 artworkItemData name:name 
                                 MIMEType:nil];
							
                     artworkMovie = [QTMovie 
                                 movieWithDataReference:
                                 dataReference error:nil];
                  }
               }
            }
         }
      }

      QTMetaDataRelease(metaDataRef);
   }

   return artworkMovie;
}

Displaying the Album Artwork

All that remains is to splice the video track from the newly-created artwork movie into the audio-only movie we have already opened. Once again, if we are using QTKit, we can do that largely with one method call, insertSegmentOfMovie:fromRange:scaledToRange:. Listing 4 shows the code we will call whenever we open a movie file. As you can see, it checks to see whether the movie is audio-only; if it is, it calls the albumArtworkMovie method defined above and inserts the video track from that movie into the audio-only movie, scaled to fit the entire duration of the audio-only movie. In effect, we've added the album artwork as a video track whose duration is the duration of the audio movie.

Listing 4: Displaying the album artwork

QTMovie *movie = [movieView movie];

if ([[movie attributeForKey:
            QTMovieHasVideoAttribute] boolValue] == NO) {
   QTMovie *artworkMovie = [movie albumArtworkMovie];

   if (artworkMovie) {
      QTTimeRange fromRange = QTMakeTimeRange(QTZeroTime, 
                                          [artworkMovie duration]);
      QTTimeRange toRange = QTMakeTimeRange(QTZeroTime,
                                [movie duration]);

      [movie insertSegmentOfMovie:artworkMovie 
            fromRange:fromRange scaledToRange:toRange];
      NSSize size = [[movie attributeForKey:
                           QTMovieNaturalSizeAttribute] sizeValue];
      [[movieView window] setContentSize:
            [self windowContentSizeForMovieSize:size]];
   }
}

And so we are done figuring out how to extract and display the album artwork contained in many iTunes music files. I should mention that MP3 files can also contain artwork data, but the QuickTime MP3 movie importer does not currently copy that data into the imported QuickTime movie. So, although our albumArtworkMovie method works fine for m4p and m4a files, it will return nil for any mp3 files opened by our application. Future versions of QuickTime may change this behavior.

Conclusion

In this article, we've taken a look at the improved metadata architecture introduced in QuickTime 7. We've seen that it supports a number of different storage formats, including iTunes metadata, classic user data, and the new QuickTime metadata format. And we seen how to use the new metadata APIs to get and set specific metadata information. In general, applications adding metainformation to QuickTime movie files should use the QuickTime metadata format instead of the existing user data format.

Acknowledgements and References

The album artwork extraction code borrows heavily from code written by Kevin Calhoun.

The QuickTime sample code repository on the Apple web site contains a sample application called QTMetaData, which shows how to use the metadata functions to display the metadata in a movie file (or other file openable by QuickTime). You will want to make one minor change to the code, however. Currently, it will crash if you try to open an MP4 file that contains album artwork. In the routine GetDataTypePropValueAndSizeAsString, you'll want to make sure that the theStringRef variable is non-NULL before passing it to CFStringAppend or CFRelease.


Tim Monroe is a member of the QuickTime engineering team at Apple. You can contact him at monroe@mactech.com. The views expressed here are not necessarily shared by his employer.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.