获取 AVFoundationErrorDomain 代码 =-11829 “尝试 generateCGImagesAsynchronouslyForTimes 时无法打开

Getting AVFoundationErrorDomain Code=-11829 "Cannot Open while trying generateCGImagesAsynchronouslyForTimes

我正在开发一个应用程序,可以将录制的视频上传到 youtube。但我需要为用户显示拇指图像,并且在上传操作之前也有一个修剪功能。

对于一些记录的文件,我在使用 generateCGImagesAsynchronouslyForTimes

创建缩略图时出错
 -(void)generateThumbnailsForAsset:(AVAsset *)asset thumbnailCount:(int)thumbnailCount andCompletionHandler:(void (^)(NSArray* thumbnailsArray))completionHandler
{
NSMutableArray *imagesArray = [[NSMutableArray alloc] init];
_imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];

KMSDebugLog(@"generateThumbnailsForAsset");
if (thumbnailCount == 1)
{
    _imageGenerator.maximumSize = PREVIEW_IMAGE_SIZE;
}
else
{
    _imageGenerator.maximumSize = THUMBNAIL_SIZE;
}

CMTime duration = asset.duration;
AVAssetTrack *videoAssetTrack= [[asset tracksWithMediaType:AVMediaTypeVideo] lastObject];
CGAffineTransform videoTransform = videoAssetTrack.preferredTransform;

UIImageOrientation videoOrientation= UIImageOrientationUp;
if(videoTransform.a == -1.0 && videoTransform.b == 0 && videoTransform.c == 0 && videoTransform.d == -1.0)
{
    videoOrientation= UIImageOrientationDown;
}
CMTimeValue intervalSeconds = duration.value / thumbnailCount;
KMSDebugLog(@"duration.value :%lld  duration.timescale:%d",duration.value,duration.timescale);
CMTime time = kCMTimeZero;
NSMutableArray *times = [NSMutableArray array];
for (NSUInteger i = 0; i < thumbnailCount; i++) {
    [times addObject:[NSValue valueWithCMTime:time]];
    time = CMTimeAdd(time, CMTimeMake(intervalSeconds, duration.timescale));
}


/*[self.imageGenerator generateCGImagesAsynchronouslyForTimes:times completionHandler:^(CMTime requestedTime,
                                                                                      CGImageRef cgImage,
                                                                                      CMTime actualTime,
                                                                                      AVAssetImageGeneratorResult result,
                                                                                      NSError *error)*/
 [self.imageGenerator generateCGImagesAsynchronouslyForTimes:times completionHandler:^(CMTime requestedTime,
                                                                                       CGImageRef cgImage,
                                                                                       CMTime actualTime,
                                                                                       AVAssetImageGeneratorResult result,
                                                                                       NSError *error)

 {
     if (error)
     {
         KMSDebugLog(@"generateCGImagesAsynchronouslyForTimes Error: %@",error);
         completionHandler(imagesArray);
     }
     else
     {
         if (cgImage)
         {
             UIImage *image = [UIImage imageWithCGImage:cgImage];

             //Orientation support
             //UIImage *image = [UIImage imageWithCGImage:cgImage scale:1.0 orientation:videoOrientation];
             // NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
             UIImage *rotatedImage = image;
             if(videoTransform.a == -1.0 && videoTransform.b == 0 && videoTransform.c == 0 && videoTransform.d == -1.0)
             {
                 rotatedImage = [self imageRotatedByDegrees:image deg:180];
             }

             [imagesArray addObject:rotatedImage];

         }

         if (imagesArray.count == thumbnailCount)
         {
             dispatch_async(dispatch_get_main_queue(), ^{
                 completionHandler(imagesArray);
             });
         }
     }
 }];
 }

错误

 Line: 265, generateCGImagesAsynchronouslyForTimes Error: Error Domain=AVFoundationErrorDomain
 Code=-11829 "Cannot Open" UserInfo={NSLocalizedDescription=Cannot Open,
 NSUnderlyingError=0x176f08b0 {Error Domain=NSOSStatusErrorDomain Code=-12848 "(null)"}, 
NSLocalizedFailureReason=This media may be damaged.}

我无法弄清楚这个问题,我们将不胜感激。谢谢

我得到了答案。我只是在录制完成后添加了一些延迟。

   [self performSelector:@selector(UpdateVideoAndConfigureScreenForURL:) withObject:videoURL afterDelay:0.2];