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

Ableton Live 11.3.11 - Record music usin...
Ableton Live lets you create and record music on your Mac. Use digital instruments, pre-recorded sounds, and sampled loops to arrange, produce, and perform your music like never before. Ableton Live... Read more
Affinity Photo 2.2.0 - Digital editing f...
Affinity Photo - redefines the boundaries for professional photo editing software for the Mac. With a meticulous focus on workflow it offers sophisticated tools for enhancing, editing and retouching... Read more
SpamSieve 3.0 - Robust spam filter for m...
SpamSieve is a robust spam filter for major email clients that uses powerful Bayesian spam filtering. SpamSieve understands what your spam looks like in order to block it all, but also learns what... Read more
WhatsApp 2.2338.12 - Desktop client for...
WhatsApp is the desktop client for WhatsApp Messenger, a cross-platform mobile messaging app which allows you to exchange messages without having to pay for SMS. WhatsApp Messenger is available for... Read more
Fantastical 3.8.2 - Create calendar even...
Fantastical is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun: Open Fantastical with a single click or keystroke Type in your event details... Read more
iShowU Instant 1.4.14 - Full-featured sc...
iShowU Instant gives you real-time screen recording like you've never seen before! It is the fastest, most feature-filled real-time screen capture tool from shinywhitebox yet. All of the features you... Read more
Geekbench 6.2.0 - Measure processor and...
Geekbench provides a comprehensive set of benchmarks engineered to quickly and accurately measure processor and memory performance. Designed to make benchmarks easy to run and easy to understand,... Read more
Quicken 7.2.3 - Complete personal financ...
Quicken makes managing your money easier than ever. Whether paying bills, upgrading from Windows, enjoying more reliable downloads, or getting expert product help, Quicken's new and improved features... Read more
EtreCheckPro 6.8.2 - For troubleshooting...
EtreCheck is an app that displays the important details of your system configuration and allow you to copy that information to the Clipboard. It is meant to be used with Apple Support Communities to... Read more
iMazing 2.17.7 - Complete iOS device man...
iMazing is the world’s favourite iOS device manager for Mac and PC. Millions of users every year leverage its powerful capabilities to make the most of their personal or business iPhone and iPad.... Read more

Latest Forum Discussions

See All

Motorsport legends NASCAR announce an up...
NASCAR often gets a bad reputation outside of America, but there is a certain charm to it with its close side-by-side action and its focus on pure speed, but it never managed to really massively break out internationally. Now, there's a chance... | Read more »
Skullgirls Mobile Version 6.0 Update Rel...
I’ve been covering Marie’s upcoming release from Hidden Variable in Skullgirls Mobile (Free) for a while now across the announcement, gameplay | Read more »
Amanita Design Is Hosting a 20th Anniver...
Amanita Design is celebrating its 20th anniversary (wow I’m old!) with a massive discount across its catalogue on iOS, Android, and Steam for two weeks. The announcement mentions up to 85% off on the games, and it looks like the mobile games that... | Read more »
SwitchArcade Round-Up: ‘Operation Wolf R...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 21st, 2023. I got back from the Tokyo Game Show at 8 PM, got to the office here at 9:30 PM, and it is presently 11:30 PM. I’ve done what I can today, and I hope you enjoy... | Read more »
Massive “Dark Rebirth” Update Launches f...
It’s been a couple of months since we last checked in on Diablo Immortal and in that time the game has been doing what it’s been doing since its release in June of last year: Bringing out new seasons with new content and features. | Read more »
‘Samba De Amigo Party-To-Go’ Apple Arcad...
SEGA recently released Samba de Amigo: Party-To-Go () on Apple Arcade and Samba de Amigo: Party Central on Nintendo Switch worldwide as the first new entries in the series in ages. | Read more »
The “Clan of the Eagle” DLC Now Availabl...
Following the last paid DLC and free updates for the game, Playdigious just released a new DLC pack for Northgard ($5.99) on mobile. Today’s new DLC is the “Clan of the Eagle" pack that is available on both iOS and Android for $2.99. | Read more »
Let fly the birds of war as a new Clan d...
Name the most Norse bird you can think of, then give it a twist because Playdigious is introducing not the Raven clan, mostly because they already exist, but the Clan of the Eagle in Northgard’s latest DLC. If you find gathering resources a... | Read more »
Out Now: ‘Ghost Detective’, ‘Thunder Ray...
Each and every day new mobile games are hitting the App Store, and so each week we put together a big old list of all the best new releases of the past seven days. Back in the day the App Store would showcase the same games for a week, and then... | Read more »
Urban Open-World RPG ‘Project Mugen’ Fro...
Last month, NetEase Games revealed a new free to play open world RPG tentatively titled Project Mugen for mobile, PC, and consoles. I’ve liked the setting and aesthetic since its first trailer, and today’s new video has the Game Designer and... | Read more »

Price Scanner via MacPrices.net

Apple AirPods 2 with USB-C now in stock and o...
Amazon has Apple’s 2023 AirPods Pro with USB-C now in stock and on sale for $199.99 including free shipping. Their price is $50 off MSRP, and it’s currently the lowest price available for new AirPods... Read more
New low prices: Apple’s 15″ M2 MacBook Airs w...
Amazon has 15″ MacBook Airs with M2 CPUs and 512GB of storage in stock and on sale for $1249 shipped. That’s $250 off Apple’s MSRP, and it’s the lowest price available for these M2-powered MacBook... Read more
New low price: Clearance 16″ Apple MacBook Pr...
B&H Photo has clearance 16″ M1 Max MacBook Pros, 10-core CPU/32-core GPU/1TB SSD/Space Gray or Silver, in stock today for $2399 including free 1-2 day delivery to most US addresses. Their price... Read more
Switch to Red Pocket Mobile and get a new iPh...
Red Pocket Mobile has new Apple iPhone 15 and 15 Pro models on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide service using all the major... Read more
Apple continues to offer a $350 discount on 2...
Apple has Studio Display models available in their Certified Refurbished store for up to $350 off MSRP. Each display comes with Apple’s one-year warranty, with new glass and a case, and ships free.... Read more
Apple’s 16-inch MacBook Pros with M2 Pro CPUs...
Amazon is offering a $250 discount on new Apple 16-inch M2 Pro MacBook Pros for a limited time. Their prices are currently the lowest available for these models from any Apple retailer: – 16″ MacBook... Read more
Closeout Sale: Apple Watch Ultra with Green A...
Adorama haș the Apple Watch Ultra with a Green Alpine Loop on clearance sale for $699 including free shipping. Their price is $100 off original MSRP, and it’s the lowest price we’ve seen for an Apple... Read more
Use this promo code at Verizon to take $150 o...
Verizon is offering a $150 discount on cellular-capable Apple Watch Series 9 and Ultra 2 models for a limited time. Use code WATCH150 at checkout to take advantage of this offer. The fine print: “Up... Read more
New low price: Apple’s 10th generation iPads...
B&H Photo has the 10th generation 64GB WiFi iPad (Blue and Silver colors) in stock and on sale for $379 for a limited time. B&H’s price is $70 off Apple’s MSRP, and it’s the lowest price... Read more
14″ M1 Pro MacBook Pros still available at Ap...
Apple continues to stock Certified Refurbished standard-configuration 14″ MacBook Pros with M1 Pro CPUs for as much as $570 off original MSRP, with models available starting at $1539. Each model... Read more

Jobs Board

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
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
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
Retail Key Holder- *Apple* Blossom Mall - Ba...
Retail Key Holder- APPLE BLOSSOM MALL Brand: Bath & Body Works Location: Winchester, VA, US Location Type: On-site Job ID: 03YM1 Job Area: Store: Sales and Support 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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.