【问题标题】:saving metadata to a video in savedPhotoAlbum Xcode将元数据保存到 savedPhotoAlbum Xcode 中的视频
【发布时间】:2017-03-10 20:37:21
【问题描述】:

当我使用 UIImagePickerController 拍摄视频并将其保存到 SavedPhotosAlbum 时使用

 ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
   [library writeVideoAtPathToSavedPhotosAlbum:(NSURL *)movieURL
    completionBlock:^(NSURL *assetURL, NSError *error){
    if (error) {
    NSLog(@"Save video fail:%@",error);
    } else {
    NSLog(@"Save video succeed.");
     [self getsavedvideo];
     }}];

保存的文件包含名称和创建日期,但不包含 GPS 信息。我对此感到惊讶,因为我使用的是内置相机和 imagePicker。为什么 Apple 不只包含 GPS 坐标(即使我必须征得用户使用定位服务的权限)。

反正我离题了

我还没有找到将 GPS 坐标添加到视频的方法,因为它正在保存,我也无法找到在 completionBlock 中添加此信息。

如果有人知道怎么做,请告诉我。

所以我写了一段在视频保存后调用的代码 [self getsavedvideo];上面获取保存的视频,我可以获取电影名称和创建日期,它显示没有位置信息。

 -(void) getsavedvideo;{
   ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
  // Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
   [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group,     BOOL *stop) {
   // Within the group enumeration block, filter to enumerate just photos.
  [group setAssetsFilter:[ALAssetsFilter allVideos]];
    // Chooses the photo at the last index
    [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset,   NSUInteger index, BOOL *innerStop) {
     // The end of the enumeration is signaled by asset == nil.
      if (alAsset) {
     ALAssetRepresentation *representation = [alAsset defaultRepresentation];
     // Stop the enumerations
     *stop = YES; *innerStop = YES;
      // Do something interesting with the AV asset.
      NSString *fileName = [representation filename];
       NSDate *myDate = [alAsset valueForProperty:ALAssetPropertyDate];
       CLLocation *location = [alAsset valueForProperty:ALAssetPropertyLocation];
       NSLog(@"fileName!!!!,%@",fileName);
       NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
      [dateFormatter setDateFormat:mad:"dd-MM-yyyy 'at' HH:mm"];
       NSLog( @"date for this file is %@ %@", [[[alAsset defaultRepresentation] url] absoluteString],   [dateFormatter stringFromDate: myDate] );
        NSLog (@"locate!!!!%@",location);
         } }];
        } failureBlock: ^(NSError *error) {
         NSLog(@"No groups");}];}

所以有谁知道如何将其附加到 GPS 信息中并将其保存回视频的元数据。 这几天我一直在绞尽脑汁,并没有真正找到任何有用的东西。

请帮忙

【问题讨论】:

    标签: ios xcode metadata uiimagepickercontroller alassetslibrary


    【解决方案1】:

    所以我还是为运行 ios8 或更新版本的设备解决了这个问题。

    将此代码添加到上述完成块中的 -(void) getsavedvideo 中。

    确保你有

    进口

    if ([PHAsset class]) { // If this class is available, we're running iOS 8
    
            PHFetchOptions *fetchOptions = [PHFetchOptions new];
            fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
            fetchOptions.fetchLimit = 1;
            PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:fetchOptions];
            PHAsset *lastImageAsset = [fetchResult lastObject];
    
            [[PHImageManager defaultManager]requestImageForAsset:lastImageAsset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:nil resultHandler:^(UIImage *result, NSDictionary *info){
                if ([info objectForKey:PHImageErrorKey] == nil && ![[info objectForKey:PHImageResultIsDegradedKey] boolValue]) {
    
                    NSArray *resources = [PHAssetResource assetResourcesForAsset:lastImageAsset];
                    NSString *orgFilename = ((PHAssetResource*)resources[0]).originalFilename;
    
    
    
                    [lastImageAsset requestContentEditingInputWithOptions:nil
                                               completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
                                                   NSURL *imageURL = contentEditingInput.fullSizeImageURL;
                                                   NSString *urlstring = [imageURL absoluteString];
                                                   NSLog(@"urlstring%@",urlstring);
                                               }];
    
    
    
                    CLLocationCoordinate2D    locationNew = CLLocationCoordinate2DMake( currentLocation.coordinate.latitude, currentLocation.coordinate.longitude) ;
                    NSDate *nowDate = [NSDate date];
    
                    CLLocation *myLocation = [[CLLocation alloc ]initWithCoordinate:locationNew altitude:0.0 horizontalAccuracy:1.0 verticalAccuracy:1.0 timestamp:nowDate];
    
    
                    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
                        // Create a change request from the asset to be modified.
                        PHAssetChangeRequest *request = [PHAssetChangeRequest changeRequestForAsset:lastImageAsset];
                        // Set a property of the request to change the asset itself.
                        request.location = myLocation;
    
                    } completionHandler:^(BOOL success, NSError *error) {
                        NSLog(@"Finished updating asset. %@", (success ? @"Success." : error));
                    }];
                }
           }];
        }
    
    
        else {
              //if you aren't running ios8 or newer I haven't found a way to add/change metadata but I will keep looking.So if you leave this blank no new metadata is added.
    }
    

    您可以添加其他元数据,只需以所需的形式创建数据,然后使用请求。(您要更改的内容)= 新数据。

    您可以通过输入类似的内容来检查数据是否已经存在以及是否有元数据

    lastImageAsset(这是上面的 PHAsset 获取结果),然后是类似的属性

    NSDate *originalFileDate = [lastImageAsset 创建日期];等等。 有一个清单 https://developer.apple.com/reference/photos/phasset

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 2011-05-28
      • 1970-01-01
      • 2020-05-20
      • 2012-11-21
      相关资源
      最近更新 更多