通过 AVAssetReader 读取示例
如何通过 AVAssetReader 读取示例?我找到了使用 AVAssetReader 复制或混合的示例,但这些循环始终由 AVAssetWriter 循环控制。是否可以只创建一个 AVAssetReader 并阅读它,获取每个样本?
谢谢。
How do you read samples via AVAssetReader? I've found examples of duplicating or mixing using AVAssetReader, but those loops are always controlled by the AVAssetWriter loop. Is it possible just to create an AVAssetReader and read through it, getting each sample?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的问题中不清楚您是在谈论视频样本还是音频样本。要读取视频示例,您需要执行以下操作:
构建 AVAssetReader:
asset_reader = [[AVAssetReader alloc] initWithAsset:资产错误:&错误];
(错误检查在此处)
从您的资源中获取视频轨道:
NSArray* video_tracks = [资源tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack* video_track = [video_tracks objectAtIndex:0];
设置所需的视频帧格式:
请注意,某些视频格式无法正常工作,如果您实时执行某些操作,某些视频格式的性能会比其他格式更好(例如,BGRA 比 ARGB 更快)。
构造实际的轨道输出并将其添加到资产读取器:
启动资产读取器:
[asset_reader startReading];
读取示例:
It's unclear from your question whether you are talking about video samples or audio samples. To read video samples, you need to do the following:
Construct an AVAssetReader:
asset_reader = [[AVAssetReader alloc] initWithAsset:asset error:&error];
(error checking goes here)
Get the video track(s) from your asset:
NSArray* video_tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack* video_track = [video_tracks objectAtIndex:0];
Set the desired video frame format:
Note that certain video formats just will not work, and if you're doing something real-time, certain video formats perform better than others (BGRA is faster than ARGB, for instance).
Construct the actual track output and add it to the asset reader:
Kick off the asset reader:
[asset_reader startReading];
Read off the samples:
达米安的答案对我来说适用于视频,并进行了一个小的修改:在步骤 3 中,我认为字典需要是可变的:
damian's answer worked for me with video, and one minor modification: In step 3, I think the dictionary needs to be mutable: