2016-07-05 1 views
2

이 방법을 사용하여 (이 질문의 끝) 장치에서 비디오를 검색합니다. 이 작업을 수행하면 라이브러리의 첫 번째 비디오를 찾고 내보내기 세션을 만들고 MOV 파일로 비디오를 내 보냅니다.PhotoKit (PHAsset)를 사용하여 비디오를 내보낼 때마다 서로 다른 비디오 파일을 제공합니다.

두 번의 응용 프로그램 실행 (메서드 실행간에 응용 프로그램 중지) 후에 두 개의 결과 파일이 비교됩니다. 두 파일 모두 다릅니다. 동일한 파일을 내보낼 때 두 파일이 동일 할 것으로 예상했습니다.

한 번 더 언급 : 동일한 응용 프로그램 실행에서 메서드를 두 번 실행하면 두 개의 동일한 파일이 예상 한대로 제공됩니다.

실행될 때마다 동일한 파일을 내보내도록 PhotoKit을 만들 수 있습니까?

- (void)testVideoRetrievalSO { 

    PHAsset *oneVideo = [[PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:nil] firstObject]; 

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


    [[PHImageManager defaultManager] requestExportSessionForVideo:oneVideo 
                  options:options 
                exportPreset:AVAssetExportPresetPassthrough 
                resultHandler: 
    ^(AVAssetExportSession * _Nullable exportSession, NSDictionary * _Nullable info) { 
     NSLog(@"Video test run on asset %@", oneVideo.localIdentifier); 
     NSString *folderPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject; 
     NSString *fileName = [[[NSUUID UUID] UUIDString] stringByAppendingPathExtension:@"mov"]; 
     NSString *tempFile = [folderPath stringByAppendingPathComponent:fileName]; 
     NSURL *tempFileUrl = [NSURL fileURLWithPath:tempFile]; 

     [exportSession setOutputFileType:AVFileTypeQuickTimeMovie]; 
     [exportSession setOutputURL:tempFileUrl]; 

     [exportSession exportAsynchronouslyWithCompletionHandler:^{ 
      NSLog(@"Video test run exported video into file: %@", tempFile); 
     }]; 
    }]; 
} 
+0

같은 비디오 파일을 얻을 수있는 솔루션을 찾았나요? 나는 또한 그것을하려고하고 내 문제는 비디오의 메타 데이터가 카메라 롤의 메타 데이터와 다르다는 것이다. –

+0

이렇게 할 수없는 것 같습니다. 적어도, 나는 대답을 찾을 수 없었다 – UrK

+0

아래 답변은 어떻습니까? –

답변

4

그것은 분명하지 않다 업데이트하지만 카메라 롤에서 비디오를 수출하는 모든 시간에 동일한 비디오를 가져 오는 보장하지 않습니다 생각합니다. 그래서 카메라 롤에서 내 문서 폴더에 URL (avurlasset.URL)을 사용하여 [NSFileManager copyItemAtURL : toURL : error :]으로 복사 한 다음 매번 동일한 비디오 파일을 복사합니다. 당분간 그것은 내 마지막 해결책입니다. 당신이 requestAVAssetForVideo하지 requestExportSessionForVideo 귀하의 경우 그래서

를 사용해야이 경우

,

PHVideoRequestOptions *options = [PHVideoRequestOptions new]; 
options.version = PHVideoRequestOptionsVersionOriginal; 

[[PHImageManager defaultManager] requestAVAssetForVideo:asset 
               options:options 
              resultHandler: 
^(AVAsset * _Nullable avasset, 
    AVAudioMix * _Nullable audioMix, 
    NSDictionary * _Nullable info) 
{ 
    NSError *error; 
    AVURLAsset *avurlasset = (AVURLAsset*) avasset; 

    // Write to documents folder 
    NSURL *fileURL = [NSURL fileURLWithPath:tmpShareFilePath]; 
    if ([[NSFileManager defaultManager] copyItemAtURL:avurlasset.URL 
               toURL:fileURL 
               error:&error]) { 
     NSLog(@"Copied correctly"); 
    } 
}]; 
+0

나를 위해 작동합니다. 권장하는대로 비디오를 내보내는 대신 직접'AVAsset'의 URL에 액세스하는 단점은 무엇입니까? – UrK

+0

@UrK 이것은 불리한 점이나 이점에 대한 문제는 아니지만이 비디오를 사용하는 방법이나 장소에 달려 있다고 생각합니다. 내보내기의 경우 조정 된 비디오 품질 또는 크기 옵션을 통해 요청할 수 있지만 경험 한대로 예상 한 것과 동일한 비디오를 내보낼 수는 없습니다. (모든 옵션을 시도하고 미리 설정하고 16 진수 수준과 비교했지만 항상 차이점이 있음) 비디오를 복사 할 때 카메라 롤에 저장된 동일한 비디오를 얻을 수있었습니다. –