我有一個讀取H264視頻文件的功能。我想用它來順序讀取許多視頻文件。它似乎適用於文件(隨機時間),部分文件失敗(讀取一些文件而不是全部文件),然後完全失敗(讀取0幀)。我通過循環播放相同的視頻文件來測試它,所以這種不確定性很奇怪。使用AVAssetReader順序讀取視頻文件在OSX Lion中失敗
該錯誤消息我得到的是:
錯誤域= AVFoundationErrorDomain代碼= -11800 「操作無法完成」 的UserInfo = {0x105d07480 = NSLocalizedFailureReason出現未知錯誤(-6662),NSLocalizedDescription =操作無法完成,NSUnderlyingError = 0x100159350「操作無法完成(OSStatus錯誤-6662。)」}
我使用ARC和OSX Lion。任何幫助深表感謝:
void uncompressMovie(NSString *moviePath) {
AVAsset *asset = [AVAsset assetWithURL:[NSURL fileURLWithPath:moviePath]];
NSArray* video_tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *video_track = [video_tracks objectAtIndex:0];
// Decompress to ARGB with the asset reader
NSDictionary *decompressionVideoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32ARGB], (id)kCVPixelBufferPixelFormatTypeKey,
[NSDictionary dictionary], (id)kCVPixelBufferIOSurfacePropertiesKey,
nil];
AVAssetReaderTrackOutput *asset_reader_output = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:video_track outputSettings:decompressionVideoSettings];
NSError *error = [[NSError alloc] init];
AVAssetReader *asset_reader = [[AVAssetReader alloc] initWithAsset:asset error:&error];
if ([asset_reader canAddOutput:asset_reader_output]) {
[asset_reader addOutput:asset_reader_output];
if ([asset_reader startReading] == YES) {
int count = 0;
while ([asset_reader status]==AVAssetReaderStatusReading) {
sampleBuffer = [asset_reader_output copyNextSampleBuffer];
if (sampleBuffer == NULL) {
if ([asset_reader status] == AVAssetReaderStatusFailed)
break;
else
continue;
}
count++;
// Will do some work here
CFRelease(sampleBuffer);
}
if (count == 0) {
NSLog(@"I am doomed %@", [asset_reader error]);
exit(1);
}
NSLog(@"Processed %d frames from %@", count, moviePath);
} else
NSLog(@"Couldn't start");
}
if ([asset_reader status] != AVAssetReaderStatusCompleted)
[asset_reader cancelReading];
// unlink([moviePath UTF8String]);
}
該問題指出,您在閱讀多個視頻文件時遇到困難,但描述和示例代碼似乎不處理多個文件。除非我錯過了一些東西,否則你應該改善問題的語言。 –
我已將其更改爲顯示我的文件背靠背而不是同時讀取多個文件 –