Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file Url of Slow motion video from Asset?

I am getting file url of normal video, but slow motion video asset type is AVComposition. I am try with AVAssetExportSession But it consuming large time.

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

[[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset *avAsset, AVAudioMix *audioMix, NSDictionary *info) {

     if(([avAsset isKindOfClass:[AVComposition class]] && ((AVComposition *)avAsset).tracks.count == 2)) {

         //Output URL of the slow motion file.
         NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
         NSString *documentsDirectory = paths.firstObject;
         NSString *myPathDocs =  [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"mergeSlowMoVideo-%d.mov",arc4random() % 1000]];
         NSURL *url = [NSURL fileURLWithPath:myPathDocs];

         //Begin slow mo video export
         AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPresetHighestQuality];
         exporter.outputURL = url;
         exporter.outputFileType = AVFileTypeQuickTimeMovie;
         exporter.shouldOptimizeForNetworkUse = YES;

         [exporter exportAsynchronouslyWithCompletionHandler:^{

             dispatch_async(dispatch_get_main_queue(), ^{
                 if (exporter.status == AVAssetExportSessionStatusCompleted) {
                 }
             });
         }];
     } else if ([avAsset isKindOfClass:[AVURLAsset class]]) {
     }
 }];
like image 948
ishwar lal janwa Avatar asked Aug 02 '17 11:08

ishwar lal janwa


1 Answers

PHImageRequestOptions.version property's default value is PHImageRequestOptionsVersionCurrent.

Simply assign the version to PHImageRequestOptionsVersionUnadjusted or PHImageRequestOptionsVersionOriginal will return the original slow motion video.

PHImageRequestOptions * options = [[PHImageRequestOptions alloc] init];

options.version = PHImageRequestOptionsVersionUnadjusted;
// or 
options.version = PHImageRequestOptionsVersionOriginal;

Hope this is useful to someone.

like image 93
Asif Newaz Avatar answered Oct 14 '22 01:10

Asif Newaz