I have an app that the user can either pick a video from device photos or take a video and then save it to the apps documents directory. I want to fill in some text fields with the creation date of the video. I can fill in current time and date when the video is taken but I want to get the creation info from the video's metadata when it is picked from the photos camera roll.
I have tried many methods with no success.
this is one method:
[/INDENT][/INDENT][/INDENT]
I have tried many methods with no success.
this is one method:
Code:
[INDENT][INDENT] NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ;
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:movieURL
resultBlock:^(ALAsset*asset) {
NSDate *myDate = [asset valueForProperty:ALAssetPropertyDate];
NSLog(@"Date: %@", myDate);
} failureBlock:^(NSError *error) {
NSLog(@"Error");
}];[/INDENT][/INDENT]
this is another
[INDENT][INDENT] CGImageSourceRef source = CGImageSourceCreateWithURL( (CFURLRef)movieURL, NULL);
NSDictionary* metadata = (NSDictionary *)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source,0,NULL));
NSLog(@"image data %@", metadata);[/INDENT][/INDENT]
this is another
//this is inside picker finished picking method
[INDENT][INDENT][INDENT][self metadata:movieURL];
-(void)metadata:(NSURL *)url
{
PHAsset *asset=[PHAsset fetchAssetsWithALAssetURLs:mad: options:nil].firstObject; if (asset) { // get photo info from this asset PHImageRequestOptions * imageRequestOptions = [[PHImageRequestOptions alloc] init]; imageRequestOptions.synchronous = YES; [[PHImageManager defaultManager] requestImageDataForAsset:asset options:imageRequestOptions resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) { [self metadataFromImageData:imageData];// as this imageData is in NSData format so we need a method to convert this NSData into NSDictionary to display metadata }]; } else { NSLog(@"no asset"); } } -(NSDictionary*)metadataFromImageData:(NSData*)imageData{ CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)(imageData), NULL); if (imageSource) { NSDictionary *options = @{(NSString *)kCGImageSourceShouldCache : [NSNumber numberWithBool:NO]}; CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (__bridge CFDictionaryRef)options); if (imageProperties) { NSDictionary *metadata = (__bridge NSDictionary *)imageProperties; CFRelease(imageProperties); CFRelease(imageSource); NSLog(@"Metadata of selected image%@",metadata);// It will display the metadata of image after converting NSData into NSDictionary return metadata; } CFRelease(imageSource); } NSLog(@"Can't read metadata"); return nil; }[/INDENT][/INDENT][/INDENT] nothing seems to work My movieURL log is [INDENT][INDENT][INDENT]2016-10-13 09:58:51.045271 my little world app[2641:1388034] movieURL;file:///private/var/mobile/Containers/Data/Application/22A178E5-74C4- 48EF-B487- 5E01321508AD/tmp/trim.04F0AC8A-2960-464D-8670-7E79662EAB9B.MOV I would really appreciate some help with this as I have spent hrs and hrs trying to figure this out and there seems to be nothing on the internet[/INDENT][/INDENT][/INDENT]
Last edited by a moderator: