1

我正在尝试使用AVAssetExportSession来更改文件的元数据,但我尝试使用的任何元数据似乎都不起作用。当我将一个空数组传递给[AVAssetExportSession setMetadata:Array];文件时,它的未编辑元数据会像它应该的那样被写入,但是一旦我将一个AVMetadataItem放入数组中,就不会将元数据写入新文件。这是我使用的代码:

//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;
    }
}];
4

1 回答 1

4

我已经回答了我自己的问题。我要更改文件信息的文件是 MP4 格式,所以我也将文件类型输出设置为 MP4。这不会导出元数据,将其更改为可以很好setOutputFileTypeAVFileTypeAppleM4V完成工作,有趣的是,输出文件仍然是 MP4,而不是 M4V。

于 2014-05-21T15:16:54.377 回答