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

Whitethorn Games combines two completely...
If you have ever gone fishing then you know that it is a lesson in patience, sitting around waiting for a bite that may never come. Well, that's because you have been doing it wrong, since as Whitehorn Games now demonstrates in new release Skate... | Read more »
Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »

Price Scanner via MacPrices.net

B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for up to $150 off Apple’s new MSRP, starting at only $849. Free 1-2 day delivery is available to most US... Read more
M2 Mac minis on sale for $100-$200 off MSRP,...
B&H Photo has Apple’s M2-powered Mac minis back in stock and on sale today for $100-$200 off MSRP. Free 1-2 day shipping is available for most US addresses: – Mac mini M2/256GB SSD: $499, save $... Read more
Mac Studios with M2 Max and M2 Ultra CPUs on...
B&H Photo has standard-configuration Mac Studios with Apple’s M2 Max & Ultra CPUs in stock today and on Easter sale for $200 off MSRP. Their prices are the lowest available for these models... Read more
Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more

Jobs Board

Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply 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
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
Business Analyst | *Apple* Pay - Banco Popu...
Business Analyst | Apple PayApply now " Apply now + Apply Now + Start applying with LinkedIn Start + Please wait Date:Mar 19, 2024 Location: San Juan-Cupey, PR Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.