gpt4 book ai didi

objective-c - 在ios中连接两个视频

转载 作者:可可西里 更新时间:2023-11-01 05:42:02 57 4
gpt4 key购买 nike

我想合并两个视频,但它总是抛出这个异常:

-[NSURL tracksWithMediaType:]: unrecognized selector sent to instance 0x935cf10

2012-08-09 16:26:59.492 videoTest[3920:17903] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[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;
}
}];

最佳答案

我通过替换这段代码修复了它:

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

与:

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality]; 

关于objective-c - 在ios中连接两个视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11882276/

57 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com