Not getting combined video even after i got a AVAssetExportSessionStatusCompleted status, objective c

Viewed 74

I was not able to get the video in the device even after getting the AVAssetExportSessionStatusCompleted status. But i was able to get the video when used in the simulator of XCode.

AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *videoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
                                                                    preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *audioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio
                                                                    preferredTrackID:kCMPersistentTrackID_Invalid];
CMTime insertTime = kCMTimeZero;

for(i=0;i<videoForMerging.count;i++) {
    AVAsset *asset = [AVAsset assetWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",videoForMerging[i]]]];
    CMTimeRange timeRange = CMTimeRangeMake(kCMTimeZero, asset.duration);

    [videoTrack insertTimeRange:timeRange
                        ofTrack:[[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
                         atTime:insertTime
                          error:nil];

    [audioTrack insertTimeRange:timeRange
                        ofTrack:[[asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
                         atTime:insertTime
                          error:nil];

    insertTime = CMTimeAdd(insertTime,asset.duration);

}
NSString* documentsDirectory= [self applicationDocumentsDirectory];
NSString *myDocumentPath= [documentsDirectory stringByAppendingPathComponent:@"merge_video.mp4"];
NSURL *urlVideoMain = [[NSURL alloc] initFileURLWithPath: myDocumentPath];

if([[NSFileManager defaultManager] fileExistsAtPath:myDocumentPath])
{
    [[NSFileManager defaultManager] removeItemAtPath:myDocumentPath error:nil];
}

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL = urlVideoMain;
exporter.outputFileType = @"com.apple.quicktime-movie";
exporter.shouldOptimizeForNetworkUse = YES;

[exporter exportAsynchronouslyWithCompletionHandler:^{

    switch ([exporter status])
    {
        case AVAssetExportSessionStatusFailed:
            break;

        case AVAssetExportSessionStatusCancelled:
            break;

        case AVAssetExportSessionStatusCompleted:
            [Util okAlert:@"Video save successfull" viewController:self];
            break;

        default:
            break;
    }
}];

}

The document directory was :

-(NSString*) applicationDocumentsDirectory { NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; return basePath; }
1 Answers
Related