PhotoKit needs an API to access the full-file content of a video

Originator:stephenpoletto
Number:rdar://18814026 Date Originated:29-Oct-2014 11:51 AM
Status:Open Resolved:
Product:iOS SDK Product Version:8.1
Classification:Enhancement Reproducible:N/A
 
Summary:
Under the iOS 8 SDK, developers do not have a straightforward way to access the full-file content of a video PHAsset.

We have tried using the following APIs:
1) -[PHImageManager requestAVAssetForVideo:options:resultHandler:]: This API often returns an AVURLAsset, from which we can open a file handle to the underlying URL to read the original bytes off disk. However, for slow-mo videos, this call returns an AVComposition, from which we cannot easily read the original bytes off disk.

2) -[PHImageManager requestExportSessionForVideo:options:exportPreset:resultHandler:]: This API returns an export session. We have tried passing AVAssetExportPresetPassthrough to the export session in order to access the original data. However, even when passing the AVAssetExportPresetPassthrough setting, the header/footer of the video container may be altered. We have noticed that the file returned from this call often has a different length than the original file. Thus, fingerprinting techniques that rely on file content & file size to establish the uniqueness of a photo/video will fail when attempting to use this API.

3)  -[PHAsset requestContentEditingInputWithOptions:completionHandler:]: This API returns a content editing input with an associated AVAsset. In our empirical studies, we have found that the AVAsset returned is always of type AVURLAsset. However, due to <rdar://18800190>, the application cannot read file content from the underlying URL of the AVURLAsset. The only workaround for this we have found is to first request an AVAsset from the requestAVAssetForVideo API and keep the returned AVAsset object alive, then call this API. Utilizing this workaround is fragile, and likely to break in future OS updates.

In both options (1) and (3) above, we need to rely on undocumented behavior (i.e. AVURLAsset being the type of AVAsset returned). Relying on such undocumented behavior is fragile.

What we need:
We need an API that gives us access to the original full-file video content, without modification to the original bytes. Photo backup applications, for instance, may have developed a "fingerprint" for the uniqueness of a photo/video by relying on the content/size of a photo/video file. We therefore need an API that returns identical full-file video content to what the iOS 7 equivalent API (-[ALAssetRepresentation getBytes:fromOffset:length:error:]) would have returned.

Steps to Reproduce:
N/A

Expected Results:
N/A

Actual Results:
N/A

Version:
iOS 8.1

Notes:


Configuration:
N/A

Attachments:

Comments

You can get access to the original URL by doing the following (this code is for illustrative purposes only):

[[PHImageManager defaultManager] requestAVAssetForVideo:firstAsset options:reqOpts resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
    if ([asset isKindOfClass:[AVComposition class]]) {
        AVComposition *comp=(AVComposition *)asset;
        AVCompositionTrack *track=[comp tracksWithMediaType:AVMediaTypeVideo].firstObject;
        AVCompositionTrackSegment *segment=track.segments.firstObject;
        NSLog(@"%@",segment.sourceURL);
        AVAsset *sourceAsset=[AVAsset assetWithURL:segment.sourceURL];
    }
}];

I do not know if this is legit for the app store or not though.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!