我正在通過AVAssetReader閱讀視頻樣本,我遇到了各種路障。可以從應用程序包中的一個名爲「Movie.m4v」的視頻設置AVAsset,並使用AVAssetReader循環播放視頻幀(CMSampleBufferRef)。閱讀視頻樣本的基本AVAssetReader問題
下面是一些我現在使用代碼不起作用的:
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");
}
資產閱讀器初始化代碼不應該很難正確。 「崩潰」並不多說,那裏到底發生了什麼? – zoul