设为首页 加入收藏

TOP

一次“Error Domain=AVFoundationErrorDomain Code=-11841”的调试(二)
2019-08-26 06:57:01 】 浏览:71
Tags:一次 Error Domain AVFoundationErrorDomain Code -11841 调试
deoComposition *)videoComposition shouldContinueva lidatingAfterFindingInvalidTimeRangeInInstruction:(id<AVVideoCompositionInstruction>)videoCompositionInstruction { NSLog(@"%s===%@",__func__,videoCompositionInstruction); return YES; } - (BOOL)videoComposition:(AVVideoComposition *)videoComposition shouldContinueva lidatingAfterFindingInvalidTrackIDInInstruction:(id<AVVideoCompositionInstruction>)videoCompositionInstruction layerInstruction:(AVVideoCompositionLayerInstruction *)layerInstruction asset:(AVAsset *)asset { NSLog(@"%s===%@===%@",__func__,layerInstruction,asset); return YES; }

重新运行一下发现第三个方法打印输出,就是instruction的timeRange问题了,又重新看了一下两个instruction的设置问题,感觉又没什么问题,代码如下:


- (void)buildCompositionWithAssets:(NSArray *)assetsArray
{
    for (int i = 0; i < assetsArray.count; i++) {
        AVURLAsset *asset = assetsArray[i];
        NSArray *videoTracks = [asset tracksWithMediaType:AVMediaTypeVideo];
        NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
        
        AVAssetTrack *videoTrack = videoTracks[0];
        AVAssetTrack *audioTrack = audioTracks[0];
        NSError *error = nil;
        AVMutableCompositionTrack *videoT = [self.avcompostions.mutableComps addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
        AVMutableCompositionTrack *audioT = [self.avcompostions.mutableComps addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
        [videoT insertTimeRange:videoTrack.timeRange ofTrack:videoTrack atTime:self.offsetTime error:&error];
        [audioT insertTimeRange:audioTrack.timeRange ofTrack:audioTrack atTime:self.offsetTime error:nil];
        NSAssert(!error, @"insert error = %@",error);
        AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
        AVMutableVideoCompositionLayerInstruction *layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoT];
        instruction.layerInstructions = @[layerInstruction];
        instruction.timeRange = CMTimeRangeMake(self.offsetTime, asset.duration);
        [self.instrucionArray addObject:instruction];
        self.offsetTime = CMTimeAdd(self.offsetTime,asset.duration);
    }
}

这个数组里面会有两个加载好的AVAsset对象,加载AVAsset的代码如下:


- (void)loadAssetFromPath:(NSArray *)paths
{
    NSMutableArray *assetsArray = [NSMutableArray arrayWithCapacity:paths.count];
    dispatch_group_t dispatchGroup = dispatch_group_create();
    for (int i = 0; i < paths.count; i++) {
        NSString *path = paths[i];
        //first find from cache
        AVAsset *asset = [self.assetsCache objectForKey:path];
        if (!asset) {
            NSDictionary *inputOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
            asset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:path] options:inputOptions];
            // cache asset
            NSAssert(asset != nil, @"Can't create asset from path", path);
            NSArray *loadKeys = @[@"tracks", @"duration", @"composable"];
            [self loadAsset:asset withKeys:loadKeys usingDispatchGroup:dispatchGroup];
            [self.assetsCache setObject:asset forKey:path];
        }else
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Knowledge-Reserve 下一篇OC重写init方法

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目