I am trying to migrate my code from ALAssetLibrary to Photos Framework, but I have a problem when I write a file to the sandbox, the size of the files generated do not match.
Writing file using 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];
Writing a file using 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:
}];
}];
The problem is that the output files are not exactly equals, when I reproduce the videos seem to be the same video, but the size of the files do not match. For example the size of a short video (2 seconds) created using ALAssetRepresentation is 229KB and with AVAssetExportSession is 227KB.
The files generated should be equals because I use a CRC based on the content of the files.
Thank you in advance.