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

Fallout Shelter pulls in ten times its u...
When the Fallout TV series was announced I, like I assume many others, assumed it was going to be an utter pile of garbage. Well, as we now know that couldn't be further from the truth. It was a smash hit, and this success has of course given the... | Read more »
Recruit two powerful-sounding students t...
I am a fan of anime, and I hear about a lot that comes through, but one that escaped my attention until now is A Certain Scientific Railgun T, and that name is very enticing. If it's new to you too, then players of Blue Archive can get a hands-on... | Read more »
Top Hat Studios unveils a new gameplay t...
There are a lot of big games coming that you might be excited about, but one of those I am most interested in is Athenian Rhapsody because it looks delightfully silly. The developers behind this project, the rather fancy-sounding Top Hat Studios,... | Read more »
Bound through time on the hunt for sneak...
Have you ever sat down and wondered what would happen if Dr Who and Sherlock Holmes went on an adventure? Well, besides probably being the best mash-up of English fiction, you'd get the Hidden Through Time series, and now Rogueside has announced... | Read more »
The secrets of Penacony might soon come...
Version 2.2 of Honkai: Star Rail is on the horizon and brings the culmination of the Penacony adventure after quite the escalation in the latest story quests. To help you through this new expansion is the introduction of two powerful new... | Read more »
The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »

Price Scanner via MacPrices.net

Verizon has Apple AirPods on sale this weeken...
Verizon has Apple AirPods on sale for up to 31% off MSRP on their online store this weekend. Their prices are the lowest price available for AirPods from any Apple retailer. Verizon service is not... Read more
Apple has 15-inch M2 MacBook Airs available s...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs available starting at $1019 and ranging up to $300 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at Apple.... Read more
May 2024 Apple Education discounts on MacBook...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take up to $300 off the purchase of a new MacBook... Read more
Clearance 16-inch M2 Pro MacBook Pros in stoc...
Apple has clearance 16″ M2 Pro MacBook Pros available in their Certified Refurbished store starting at $2049 and ranging up to $450 off original MSRP. Each model features a new outer case, shipping... Read more
Save $300 at Apple on 14-inch M3 MacBook Pros...
Apple has 14″ M3 MacBook Pros with 16GB of RAM, Certified Refurbished, available for $270-$300 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year warranty is... Read more
Apple continues to offer 14-inch M3 MacBook P...
Apple has 14″ M3 MacBook Pros, Certified Refurbished, available starting at only $1359 and ranging up to $270 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year... Read more
Apple AirPods Pro with USB-C return to all-ti...
Amazon has Apple’s AirPods Pro with USB-C in stock and on sale for $179.99 including free shipping. Their price is $70 (28%) off MSRP, and it’s currently the lowest price available for new AirPods... Read more
Apple Magic Keyboards for iPads are on sale f...
Amazon has Apple Magic Keyboards for iPads on sale today for up to $70 off MSRP, shipping included: – Magic Keyboard for 10th-generation Apple iPad: $199, save $50 – Magic Keyboard for 11″ iPad Pro/... Read more
Apple’s 13-inch M2 MacBook Airs return to rec...
Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices currently... Read more
Best Buy is clearing out iPad Airs for up to...
In advance of next week’s probably release of new and updated iPad Airs, Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices for up to $200 off Apple’s MSRP, starting at $399. Sale prices... Read more

Jobs Board

Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
*Apple* App Developer - Datrose (United Stat...
…year experiencein programming and have computer knowledge with SWIFT. Job Responsibilites: Apple App Developer is expected to support essential tasks for the RxASL Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.