AVAssetExportSession export a video in Normal Rate even video is 120FPS

522 Views Asked by At

I recorded a video in 120FPS. It is SLOW_Mo video. IF I export that video in CameraRoll using PHImageManager. Everything is ok like as VIDEO Effect is slow_mo. I can play it using QuickPlayer and AVPlayer and effect is 120FPS.

This is my working code:

  PHAsset *oneVideo = [[PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:nil] lastObject];
    PHVideoRequestOptions *options = [PHVideoRequestOptions new];
    options.networkAccessAllowed = YES;
    options.version = PHVideoRequestOptionsVersionCurrent;
    options.deliveryMode = PHVideoRequestOptionsDeliveryModeHighQualityFormat;
    [[PHImageManager defaultManager] requestAVAssetForVideo:oneVideo options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
        if(([asset isKindOfClass:[AVComposition class]])){
            BOOL bResult = FALSE;
            DebugLog(@"\navPlayer.outputFileURL.absoluteString:%@", URl);
            bResult = [[NSFileManager defaultManager] removeItemAtURL:URl error:nil];
            DebugLog(@"\nremoveItemAtPath:%d", bResult);
            //Begin slow mo video export
            AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
            exporter.outputURL = avPlayer.outputFileURL;
            // exporter.outputURL = urlFirstVideoPath;
            exporter.outputFileType = AVFileTypeQuickTimeMovie;
            exporter.shouldOptimizeForNetworkUse = YES;

            [exporter exportAsynchronouslyWithCompletionHandler:^{
                NSLog(@"Video test run exported video into file: %@", exporter.outputURL);
                NSLog(@"exportSession.status: %ld", (long)exporter.status);
                dispatch_async(dispatch_get_main_queue(), ^{
                    if (exporter.status == AVAssetExportSessionStatusCompleted) {
                        NSLog(@"exportSession.status: okkkkkkk");
                    }
                });
            }];

        }
    }];

NOW I don't want to save that video in CAMERAROLL. I saved video in Document folder. and get AVAssets. But effect is not slow_mo 120FPS I READ about it and got i should use AVComposition for export slow_mo video. but i am unable to do it. Below is my NOT working code.

    AVAsset *assetURL = [AVURLAsset URLAssetWithURL:URl options:nil];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = paths.firstObject;
    NSString *myPathDocs =  [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"mergeSlowMoVideo-%d.mov",arc4random() % 1000]];
    NSURL *_filePath = [NSURL fileURLWithPath:myPathDocs];

    AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:assetURL presetName:AVAssetExportPresetHighestQuality];
    exporter.outputURL = _filePath;
    exporter.outputFileType = AVFileTypeQuickTimeMovie;
    exporter.shouldOptimizeForNetworkUse = YES;
    [exporter exportAsynchronouslyWithCompletionHandler:^{ //start
        NSLog(@"Export failed: %@", [[exporter error] localizedDescription]);
        NSLog(@"Video test run exported video into file: %@", exporter.outputURL);
        NSLog(@"export  %ld", (long)exporter.status);
        dispatch_async(dispatch_get_main_queue(), ^{
            if (exporter.status == AVAssetExportSessionStatusCompleted) {

            }
        });
    }];

Please any expert help me.

UPDATE: this is my actual problem.

This Question has my Actual problem explanation

0

There are 0 best solutions below