我逐帧阅读 MP4 视频,所以我使用 AVAssetReader ,它总是可以正常工作,但在“startReading”方法中失败的概率为 1/100。错误域=AVFoundationErrorDomain 代码=-11841 (AVErrorInvalidVideoComposition) - (void)test{
self.reader = [AVAssetReader.alloc initWithAsset:asset error:&readerError];
if (readerError) {
_error = readerError;
return;
}
//
// Video input
//
AVAssetTrack * videoTrack = validVideoTracks.firstObject;
self.videoInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:self.videoSettings];
self.videoInput.expectsMediaDataInRealTime = NO;
self.videoInput.transform = videoTrack.preferredTransform;
if ([self.writer canAddInput:self.videoInput]) {
[self.writer addInput:self.videoInput];
}
//
// Audio input
//
if (self.audioOutput) {
self.audioInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:self.audioSettings];
self.audioInput.expectsMediaDataInRealTime = NO;
if ([self.writer canAddInput:self.audioInput]) {
[self.writer addInput:self.audioInput];
}
}
BOOL isStartReading = [self.reader startReading];
if (!isStartReading) {
NSLog(@"error :%@",self.reader.error);
}
}