我想通过AVAssetReader阅读视频样本,我遇到了各种各样的路障。某个邮政编码可以从应用程序包中的一个名为“AVAsset”的视频中设置一个Movie.m4v,并使用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");
}发布于 2011-06-21 12:31:08
很可能是因为[NSURL URLWithString:path]而崩溃。您应该使用[NSURL fileURLWithPath:path]代替。
发布于 2011-06-21 16:24:22
在使用磁道之前,您需要要求您的AVAsset异步加载其轨道属性。
https://stackoverflow.com/questions/6421170
复制相似问题