我正在尝试使用与我的应用相关的自定义元数据保存视频,并在用户从库中选择该视频时尝试检索它。我不确定我是否正确保存了元数据,因为当我尝试检索元数据时看不到任何内容。我也不确定我是否正确检索元数据。我是iOS新手,感谢任何帮助。我搜索了许多线程和开发人员库,但无法使其正常工作。
我正在尝试将元数据保存在 recordingDidFinishToOutputFileURL 委托函数中。视频正在库中保存。
NSMutableArray *metadata = [NSMutableArray array];
AVMutableMetadataItem *mi = [AVMutableMetadataItem metadataItem];
mi.key = AVMetadataCommonKeyTitle;
mi.keySpace = AVMetadataKeySpaceCommon;
mi.value = @"title";
[metadata addObject:mi];
NSLog(@"Output saving:%@",outputFileURL);
AVAsset *video = [AVAsset assetWithURL:outputFileURL];
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPresetPassthrough];
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.metadata = metadata;
exportSession.outputURL = outputFileURL;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
NSLog(@"done processing video!");
UISaveVideoAtPathToSavedPhotosAlbum(outputFileURL.path, self, @selector(video:didFinishSavingWithError: contextInfo:), nil);
}];
我正在尝试在 didFinishPickingMediaWithInfo 委托函数中检索视频以检查元数据,但在 completionhandler 函数中看不到任何内容
if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
video_selected = TRUE;
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"video has %@", videoURL.path);
AVAsset *videoAsset = [AVAsset assetWithURL:videoURL];
NSLog(@"Loading metadata...");
NSArray *keys = [[NSArray alloc] initWithObjects:@"commonMetadata", nil];
NSMutableArray *metadata = [[NSMutableArray alloc] init];
[videoAsset loadValuesAsynchronouslyForKeys:keys completionHandler:^{
[metadata removeAllObjects];
for (NSString *format in [videoAsset availableMetadataFormats])
{
[metadata addObjectsFromArray:[videoAsset metadataForFormat:format]];
NSLog(@"Printing metadata-%@",metadata);
}
}];