I read a MP4 video, frame by frame, so I use AVAssetReader , it always work ok, but 1/100 probability fail in "startReading" method. Error Domain=AVFoundationErrorDomain Code=-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);
}
}