繁体   English   中英

读取视频样本的基本AVAssetReader问题

[英]Basic AVAssetReader problems reading video samples

我想通过AVAssetReader阅读视频样本,我遇到了各种各样的路障。 可以使用应用程序包中的一个名为“Movie.m4v”的视频设置AVAsset并使用AVAssetReader循环浏览视频帧(CMSampleBufferRef)。

这里有一些我现在使用的代码不起作用

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");



}

由于[NSURL URLWithString:path]很可能崩溃。 您应该使用[NSURL fileURLWithPath:path]

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM