Exemple #1
0
/* Add the meta data that lavf exposes to the movie */
static void add_metadata(AVFormatContext *ic, Movie theMovie)
{
    QTMetaDataRef movie_metadata;
    OSType err;

    err = QTCopyMovieMetaData(theMovie, &movie_metadata);
    if (err) return;

    void (^AddMetaDataItem)(const char *, OSType) = ^(const char *ff_name, OSType qt_name) {
        AVDictionaryEntry *e = av_dict_get(ic->metadata, ff_name, NULL, 0);
        if (!e) return;

        QTMetaDataAddItem(movie_metadata, kQTMetaDataStorageFormatQuickTime, kQTMetaDataKeyFormatCommon,
                          (UInt8*)&qt_name, sizeof(qt_name), (UInt8*)e->value, strlen(e->value), kQTMetaDataTypeUTF8,
                          NULL);
    };

    AddMetaDataItem("title",     kQTMetaDataCommonKeyDisplayName);
    AddMetaDataItem("author",    kQTMetaDataCommonKeyAuthor);
    AddMetaDataItem("artist",    kQTMetaDataCommonKeyArtist);
    AddMetaDataItem("copyright", kQTMetaDataCommonKeyCopyright);
    AddMetaDataItem("comment",   kQTMetaDataCommonKeyComment);
    AddMetaDataItem("album",     kQTMetaDataCommonKeyAlbum);
    AddMetaDataItem("genre",     kQTMetaDataCommonKeyGenre);
    AddMetaDataItem("composer",  kQTMetaDataCommonKeyComposer);
    AddMetaDataItem("encoder",   kQTMetaDataCommonKeySoftware);
    // TODO iTunes track number, disc number, ...

    QTMetaDataRelease(movie_metadata);
}
Exemple #2
0
void QTImportFileHandle::AddMetadata(Tags *tags)
{
   QTMetaDataRef metaDataRef = NULL;
   auto cleanup = finally( [&] {
      // we are done so release our metadata object
      if ( metaDataRef )
         QTMetaDataRelease(metaDataRef);
   } );

   OSErr err;

   err = QTCopyMovieMetaData(mMovie, &metaDataRef);
   if (err != noErr) {
      return;
   }

   for (int i = 0; i < WXSIZEOF(names); i++) {
      QTMetaDataItem item = kQTMetaDataItemUninitialized;
      // OSType key = names[i].key;

      err = QTMetaDataGetNextItem(metaDataRef,
                                  kQTMetaDataStorageFormatWildcard,
                                  kQTMetaDataItemUninitialized,
                                  kQTMetaDataKeyFormatCommon,
                                  (const UInt8 *) &names[i].key,
                                  sizeof(names[i].key),
                                  &item);
      if (err != noErr) {
         continue;
      }

      if (item == kQTMetaDataItemUninitialized) {
         continue;
      }

      QTPropertyValueType outPropType;
      ::ByteCount outPropValueSize;
      ::ByteCount outPropValueSizeUsed = 0;
      UInt32 outPropFlags;
      UInt32 dataType;

      // Get data type
      err =  QTMetaDataGetItemProperty(metaDataRef,
                                       item,
                                       kPropertyClass_MetaDataItem,
                                       kQTMetaDataItemPropertyID_DataType,
                                       sizeof(dataType),
                                       &dataType,
                                       &outPropValueSizeUsed);
      if (err != noErr) {
         continue;
      }

      // Get the data length
      err = QTMetaDataGetItemPropertyInfo(metaDataRef,
                                          item,
                                          kPropertyClass_MetaDataItem,
                                          kQTMetaDataItemPropertyID_Value,
                                          &outPropType,
                                          &outPropValueSize,
                                          &outPropFlags );
      if (err != noErr) {
         continue;
      }

      // Alloc memory for it
      ArrayOf<char> outVals{ outPropValueSize };

      // Retrieve the data
      err =  QTMetaDataGetItemProperty(metaDataRef,
                                       item,
                                       kPropertyClass_MetaDataItem,
                                       kQTMetaDataItemPropertyID_Value,
                                       outPropValueSize,
                                       outVals.get(),
                                       &outPropValueSizeUsed);
      if (err != noErr)
         continue;

      wxString v = wxT("");

      switch (dataType)
      {
         case kQTMetaDataTypeUTF8:
            v = wxString(outVals.get(), wxConvUTF8);
         break;
         case kQTMetaDataTypeUTF16BE:
         {
            wxMBConvUTF16BE conv;
            v = wxString(outVals.get(), conv);
         }
         break;
      }

      if (!v.IsEmpty()) {
         tags->SetTag(names[i].name, v);
      }
   }

   return;
}
void DumpMovieMetaData(Movie theMovie)
{
    require(nil != theMovie, NILMOVIE);

	// get movie metadata reference which is necessary to iterate
	// all the metadata items
	QTMetaDataRef metaDataRef;
	OSStatus status = QTCopyMovieMetaData (theMovie, &metaDataRef );
	require_noerr(status, NOMETADATAREF);
			
	// get count of total number of metadata items for *all* container formats
	ItemCount outCount=0;	
	status = MDUtils_GetStorageFormatCountForAllFormats(metaDataRef, &outCount);
	
	DrawStorageCountStrToWindow("Total for all", outCount);
	DrawStringToFrontWindow(CFSTR("\n"));
	DrawStringToFrontWindow(CFSTR("details:\n"));
	DrawStringToFrontWindow(CFSTR("\n"));

	// display metadata item count values for each of the different storage formats
	ItemCount iTunesShortCount=0, iTunesLongCount=0, UserDataCount=0, QTDataCount=0;	
	status = MDUtils_GetiTunesStorageFormatShortFormCount(metaDataRef, &iTunesShortCount);
	status = MDUtils_GetiTunesStorageFormatLongFormCount(metaDataRef, &iTunesLongCount);
	status = MDUtils_GetUserDataStorageFormatCount(metaDataRef, &UserDataCount);
	status = MDUtils_GetQuickTimeDataStorageFormatCount(metaDataRef, &QTDataCount);

	DrawStorageCountStrToWindow("iTunes ShortForm", iTunesShortCount);
	DrawStorageCountStrToWindow("iTunes LongForm", iTunesLongCount);
	DrawStorageCountStrToWindow("User Data", UserDataCount);
	DrawStorageCountStrToWindow("QuickTime", QTDataCount);

	if (outCount)
	{
		DrawStringToFrontWindow(CFSTR("--------------------------------------------\n"));
		DrawStringToFrontWindow(CFSTR("Key for Metadata Item Display:\n"));
		DrawStringToFrontWindow(CFSTR("\n"));
		DrawStringToFrontWindow(CFSTR("- storage format\n"));
		DrawStringToFrontWindow(CFSTR("- key\n"));
		DrawStringToFrontWindow(CFSTR("- keyformat\n"));
		DrawStringToFrontWindow(CFSTR("- locale\n"));
		DrawStringToFrontWindow(CFSTR("- data type\n"));
		DrawStringToFrontWindow(CFSTR("- value\n"));
	}

	// iterate and display all metadata items

	QTMetaDataItem item = kQTMetaDataItemUninitialized;
	// Get the next metadata item, regardless of the type of storage format
	while (noErr == (MDUtils_GetNextItemForAnyStorageFormat(metaDataRef, item, &item)))
	{
		DrawStringToFrontWindow(CFSTR("--------------------------------------------\n"));
		
		DumpAllPropertiesForMetaDataItem(metaDataRef, item);			
	}

	// we are done so release our metadata object
	QTMetaDataRelease(metaDataRef);
	
NILMOVIE:
NOMETADATAREF:
;

}