Objective c 在ios中连接两个视频
我正在尝试合并两个视频,但它总是引发以下异常:Objective c 在ios中连接两个视频,objective-c,ios,xcode,avfoundation,Objective C,Ios,Xcode,Avfoundation,我正在尝试合并两个视频,但它总是引发以下异常: -[NSURL tracksWithMediaType:]:无法识别的选择器发送到实例0x935cf10 2012-08-09 16:26:59.492 videoTest[3920:17903]由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[NSURL tracksWithMediaType:: 代码如下: AVMutableComposition *mixComposition = [AVMu
-[NSURL tracksWithMediaType:]:无法识别的选择器发送到实例0x935cf10
2012-08-09 16:26:59.492 videoTest[3920:17903]由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[NSURL tracksWithMediaType::
代码如下:
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 = [videoClipPaths objectAtIndex:i];
AVAssetTrack *clipVideoTrackB = [[assetClip tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
[timeRanges addObject:[NSValue valueWithCMTimeRange:CMTimeRangeMake(kCMTimeZero, assetClip.duration)]];
[tracks addObject:clipVideoTrackB];
}
[compositionTrack insertTimeRanges:timeRanges ofTracks:tracks atTime:kCMTimeZero error:&error];
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPreset1280x720];
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");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(@"exporting completed");
//UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, nil, NULL);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"export cancelled");
break;
}
}];
AVMutableComposition*mixComposition=[AVMutableComposition];
AVMutableCompositionTrack*compositionTrack=[mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_无效];
n错误*错误=nil;
NSMutableArray*时间范围=[NSMutableArray阵列容量:VideoClippath.count];
NSMutableArray*跟踪=[NSMutableArray阵列容量:VideoClippath.count];
for(int i=0;iassetClip
是一个avurlaste
。但是它看起来像是在给它分配一个NSURL
对象。然后你在它上面调用tracksWithMediaType
,这是NSURL
没有的方法。这就是为什么你会得到“无法识别的选择器”
我对这个特殊的类家族不是很熟悉,但是如果替换它,它可能会解决您的问题
AVURLAsset *assetClip = [videoClipPaths objectAtIndex:i];
与
我通过替换此代码修复了它:
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPreset1280x720]; NSParameterAssert(exporter != nil);
与:
***由于未捕获异常“NSInternalInconsistencyException”而终止应用程序,原因是:“无效参数不满足:exporter!=nil”,而不是:AVAssetExportSession*exporter=[[AVAssetExportSession alloc]initWithAsset:mixComposition预设名称:AVAssetExportPreset1280x720];NSParameterAssert(exporter!=nil);我将AVAssetExportSession*exporter=[[AVAssetExportSession alloc]initWithAsset:mixComposition预设名称:AVAssetExportPresetHighestQuality];似乎还有另一个问题。很高兴看到你解决了。很抱歉,我昨天无法为你提供更多帮助。
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPreset1280x720]; NSParameterAssert(exporter != nil);
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];