设为首页 加入收藏

TOP

一次“Error Domain=AVFoundationErrorDomain Code=-11841”的调试(三)
2019-08-26 06:57:01 】 浏览:70
Tags:一次 Error Domain AVFoundationErrorDomain Code -11841 调试
{ } [assetsArray addObject:asset]; } dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^{ !self.assetLoadBlock?:self.assetLoadBlock(assetsArray); }); } - (void)loadAsset:(AVAsset *)asset withKeys:(NSArray *)assetKeysToLoad usingDispatchGroup:(dispatch_group_t)dispatchGroup { dispatch_group_enter(dispatchGroup); [asset loadValuesAsynchronouslyForKeys:assetKeysToLoad completionHandler:^(){ for (NSString *key in assetKeysToLoad) { NSError *error; if ([asset statusOfValueForKey:key error:&error] == AVKeyValueStatusFailed) { NSLog(@"Key value loading failed for key:%@ with error: %@", key, error); goto bail; } } if (![asset isComposable]) { NSLog(@"Asset is not composable"); goto bail; } bail: dispatch_group_leave(dispatchGroup); }]; }

按照正常来说,应该不会有什么问题的,但是问题还是来了。打印出创建的两个AVMutableVideoCompositionInstruction的信息,发现他们的timeRange确实有重合的地方。AVMutableVideoCompositionInstruction的timeRange必须对应AVMutableCompositionTrack里面的一段段插入的track的timeRange。开发文档是这么说的:

to report a video composition instruction with a timeRange that's invalid, that overlaps with the timeRange of a prior instruction, or that contains times earlier than the timeRange of a prior instruction

我在插入的时候使用的是videoTrack.timeRange,而设置instruction.timeRange = CMTimeRangeMake(self.offsetTime, asset.duration);使用的是asset.duration。这个两个竟然是不一样的。asset.duration是{59885/1000 = 59.885},videoTrack.timeRange是{{0/1000 = 0.000}, {59867/1000 = 59.867}}
这两个时长有细微差别,到底哪个是比较准确一点的呢?

视频文件时长的计算

笔者在demo中使用的是mp4格式的文件,mp4文件是若干个不同的类型box组成的,box可以理解为装有数据的容器。其中有一种moov类型的box里面装有视频播放的元数据(metadata),这里面有视频的时长信息:timescale和duration。 duration / timescale = 可播放时长(s)。从mvhd中读到timescal为0x03e8,duration为0xe9ed,也就是59885 / 1000,为59.885。再看看tkhd box里面的内容,这里面是包含单一track的信息。如下图:

mvhd

tkhd1_video

tkhd2_audio

从上图可以看出videotrack和audiotrack两个的时长是不一样的,videotrack为0xe9db,也就是59.867,audiotrack为0xe9ed,就是59.885。所以我们在计算timeRange的时候最好统一使用相对精确一点的videotrack,而不要AVAsset的duration,尽量避免时间上的误差,视频精细化的编辑,对这些误差敏感。

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Knowledge-Reserve 下一篇OC重写init方法

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目