2014-05-20 24 views
1

我試圖使用AVAssetExportSession來更改文件的元數據,但我嘗試使用的任何元數據似乎都不起作用。當我將一個空數組傳遞給[AVAssetExportSession setMetadata:Array];時,文件會使用其未經編輯的元數據編寫,但是隻要將AVMetadataItem放入數組中,就不會將元數據寫入新文件。這裏是我使用的代碼:AVAssetExportSession不導出元數據

//NSMutableArray *newArray = [NSMutableArray arrayWithArray:[exportSession metadata]]; 

AVMutableMetadataItem *addingNew = [[AVMutableMetadataItem alloc] init]; 
[addingNew setKeySpace:AVMetadataKeySpaceiTunes]; 
[addingNew setKey:AVMetadataiTunesMetadataKeyUserComment]; 
[addingNew setValue:[NSString stringWithFormat:@"This is my comment"]]; 

NSArray *newArray = [NSArray arrayWithObject:addingNew]; 

NSURL *fileURL = [NSURL fileURLWithPath: outputFile]; 

[exportSession setMetadata:metaMuteArray]; 
[exportSession setOutputURL:fileURL]; 
[exportSession setOutputFileType:AVFileTypeMPEG4]; 
[exportSession shouldOptimizeForNetworkUse:YES]; //false doesn't work either 

[exportSession exportAsynchronouslyWithCompletionHandler:^{ 
    switch ([exportSession status]) 
    { 
     case AVAssetExportSessionStatusCompleted: 
      NSLog(@"Export sucess"); 
     case AVAssetExportSessionStatusFailed: 
      NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]); 
     case AVAssetExportSessionStatusCancelled: 
      NSLog(@"Export canceled"); 
     default: 
      break; 
    } 
}]; 

回答

2

我已經回答了我自己的問題。我正在更改文件信息的文件是MP4格式,所以我也將文件類型輸出設置爲MP4。這不會導出元數據,將setOutputFileType更改爲AVFileTypeAppleM4V的工作很好,有趣的是輸出文件仍然是和MP4,而不是M4V。