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

Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
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 below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »

Price Scanner via MacPrices.net

Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Apple’s new 13″ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13″ M3 MacBook... Read more
You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more
Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several 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... Read more

Jobs Board

Relationship Banker - *Apple* Valley Financ...
Relationship Banker - Apple Valley Financial Center APPLE VALLEY, Minnesota **Job Description:** At Bank of America, we are guided by a common purpose to help Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.