Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用ALAssetRepresentation vs AVAssetExportSession将视频资源从摄影机卷复制到沙箱_Ios_Objective C_Avfoundation_Photosframework_Alassetlibrary - Fatal编程技术网

Ios 使用ALAssetRepresentation vs AVAssetExportSession将视频资源从摄影机卷复制到沙箱

Ios 使用ALAssetRepresentation vs AVAssetExportSession将视频资源从摄影机卷复制到沙箱,ios,objective-c,avfoundation,photosframework,alassetlibrary,Ios,Objective C,Avfoundation,Photosframework,Alassetlibrary,我正在尝试将代码从ALAssetLibrary迁移到Photos框架,但在将文件写入沙箱时遇到问题,生成的文件大小不匹配 使用ALAssetRepresentation写入文件: [[NSFileManager defaultManager] createFileAtPath:localFilePath contents:nil attributes:nil]; NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:l

我正在尝试将代码从ALAssetLibrary迁移到Photos框架,但在将文件写入沙箱时遇到问题,生成的文件大小不匹配

使用ALAssetRepresentation写入文件:

[[NSFileManager defaultManager] createFileAtPath:localFilePath contents:nil attributes:nil];  
NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:localFilePath];  

static const NSUInteger kBufferSize = 10 * 1024;  
uint8_t *buffer = calloc(kBufferSize, sizeof(*buffer));  
NSUInteger offset = 0, bytesRead = 0;  

do {  
     bytesRead = [assetRepresentation getBytes:buffer fromOffset:offset length:kBufferSize error:nil];  
     [handle writeData:[NSData dataWithBytesNoCopy:buffer length:bytesRead freeWhenDone:NO]];  
     offset += bytesRead;  
} while (bytesRead > 0);  

free(buffer);  
[handle closeFile];
使用AVAssetExportSession写入文件:

PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];  
options.version = PHVideoRequestOptionsVersionOriginal;  
options.networkAccessAllowed = YES;  

[[PHImageManager defaultManager] requestExportSessionForVideo:_phasset options:options exportPreset:AVAssetExportPresetPassthrough  
                                                           resultHandler:^(AVAssetExportSession *exportSession, NSDictionary *info) {  
             exportSession.outputURL = [NSURL fileURLWithPath:localFilePath];  
             exportSession.outputFileType = AVFileTypeQuickTimeMovie;  
             [exportSession exportAsynchronouslyWithCompletionHandler:  
     }];  
}];
问题是,当我复制视频时,输出文件并不完全相等,似乎是相同的视频,但文件的大小不匹配。 例如,使用ALAssetRepresentation创建的短视频(2秒)大小为229KB,使用AVAssetExportSession创建的短视频大小为227KB

生成的文件应该相等,因为我使用基于文件内容的CRC

提前谢谢。

顺便说一句,使用
-(void)writedatforAssetResource:(PHAssetResource*)resource to file:(NSURL*)fileURL选项:(PHAssetResourceRequestOptions*)选项completionHandler:(void(^)(NSError*error))completionHandler
编写的文件与使用
ALAssetRepresentation
编写的文件完全相同,问题是,这仅适用于iOS 9.0,如果资源在iCloud中,则此方法似乎有错误,并且没有下载asset.BTW,使用
-(void)writeDataForAssetResource:(PHAssetResource*)resource toFile:(NSURL*)fileURL选项:(PHAssetResourceRequestOptions*)选项completionHandler:(void(^)(NSError*错误))completionHandler
编写的文件与使用
ALAssetRepresentation
编写的文件完全相同,问题是这仅适用于iOS 9.0,如果资源位于iCloud中,则此方法看起来有缺陷,无法下载资源。