Exporting video using PhotoKit (PHAsset) gives different video file every time

后端 未结 1 803
你的背包
你的背包 2021-01-03 09:23

I use the method (a the end of this question) to retrieve video from the device. What it does, it finds the first video in the library, creates export session and exports th

相关标签:
1条回答
  • 2021-01-03 09:57

    UPDATED

    It's not clear but I think exporting video from the camera roll does not guarantee fetching same video in every time. So I copied the video from camera roll to my document folder with url (avurlasset.URL) by [NSFileManager copyItemAtURL:toURL:error:] then it copies the same video file in every time. For now it is my final solution.

    In this case you have to use requestAVAssetForVideo not requestExportSessionForVideo

    So in your case,

    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 讨论(0)
提交回复
热议问题