0

我正在尝试合并视频,并且代码在模拟器上运行良好。我可以合并视频,但是当我在设备上运行相同的代码时,它给了我这个异常

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'* -[__NSArrayM insertObject:atIndex:]: object cannot be nil

代码在这里:

AVMutableComposition *mixComposition = [AVMutableComposition composition]; AVMutableCompositionTrack *compositionTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; NSError * error = nil; NSMutableArray * timeRanges = [NSMutableArray arrayWithCapacity:videoClipPaths.count]; NSMutableArray * tracks = [NSMutableArray arrayWithCapacity:videoClipPaths.count]; for (int i=0; i<[videoClipPaths count]; i++) { AVURLAsset *assetClip = [AVURLAsset URLAssetWithURL:[videoClipPaths objectAtIndex:i] options:nil]; AVAssetTrack *clipVideoTrackB = [[assetClip tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];

    [timeRanges addObject:[NSValue valueWithCMTimeRange:CMTimeRangeMake(kCMTimeZero, assetClip.duration)]];
    [tracks addObject:clipVideoTrackB];
}

NSLog(@"HELLO: %@", timeRanges );
[compositionTrack insertTimeRanges:timeRanges ofTracks:tracks atTime:kCMTimeZero error:&error];

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];
// NSParameterAssert(exporter != nil);

NSArray *t; NSString *u;

t = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
u = [t objectAtIndex:0];
NSString *finalPath = [u stringByAppendingPathComponent:@"final.mov"];
NSURL *lastURL = [NSURL fileURLWithPath:finalPath];
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.outputURL = lastURL;
[exporter exportAsynchronouslyWithCompletionHandler:^(void){
    switch (exporter.status) {
        case AVAssetExportSessionStatusFailed:
            NSLog(@"exporting failed");
            [SVProgressHUD dismiss];
            break;
        case AVAssetExportSessionStatusCompleted:
            NSLog(@"exporting completed");
            UISaveVideoAtPathToSavedPhotosAlbum(finalPath, self, nil, NULL);
             [SVProgressHUD dismiss];
            break;
        case AVAssetExportSessionStatusCancelled:
            NSLog(@"export cancelled");
            break;
    }
}];
4

1 回答 1

1

很可能您的应用程序正在使用驻留在 Mac 上的某些文件,但您尚未在手机上安装并正确寻址。

但是,无论如何,记录“tracks”以及“timeRanges”。

于 2012-08-17T12:44:18.357 回答