首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >读取视频示例的基本AVAssetReader问题

读取视频示例的基本AVAssetReader问题
EN

Stack Overflow用户
提问于 2011-06-21 06:23:09
回答 2查看 5.4K关注 0票数 6

我想通过AVAssetReader阅读视频样本,我遇到了各种各样的路障。某个邮政编码可以从应用程序包中的一个名为“AVAsset”的视频中设置一个Movie.m4v,并使用AVAssetReader遍历视频帧(CMSampleBufferRef)。

下面是我现在使用的一些不起作用的代码

代码语言:javascript
复制
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Movie.m4v"];
AVAsset *avAsset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:path] options:nil];
NSError *error = nil;
AVAssetReader *reader = [[AVAssetReader alloc] initWithAsset:avAsset error:&error]; // crashing right around here!

// I've gotten avassetreader to not crash upon initialization by grabbing an asset from the ALAssetsLibrary but it says it has 0 tracks!

NSArray *videoTracks = [avAsset tracksWithMediaType:AVMediaTypeVideo]; 
AVAssetTrack *videoTrack = [videoTracks objectAtIndex:0];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
AVAssetReaderTrackOutput *asset_reader_output = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack outputSettings:options];
[reader addOutput:asset_reader_output];
[reader startReading];

CMSampleBufferRef buffer;
while ( [reader status]==AVAssetReaderStatusReading ){

    buffer = [asset_reader_output copyNextSampleBuffer];
    NSLog(@"READING");



}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-21 12:31:08

很可能是因为[NSURL URLWithString:path]而崩溃。您应该使用[NSURL fileURLWithPath:path]代替。

票数 10
EN

Stack Overflow用户

发布于 2011-06-21 16:24:22

在使用磁道之前,您需要要求您的AVAsset异步加载其轨道属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6421170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档