Nan*_*ncy 9 video metadata ios
我正在尝试使用与我的应用相关的自定义元数据保存视频,并在用户从库中选择该视频时尝试检索该视频.我不确定我是否正在保存元数据,因为当我尝试检索元数据时,我无法看到任何内容.我也不确定我是否正确检索元数据.我是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);
}];
Run Code Online (Sandbox Code Playgroud)
我试图在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);
}
}];
Run Code Online (Sandbox Code Playgroud)