2015-10-14 32 views
0

我正在開發一個應用程序無法打開在錄製的視頻上傳到YouTube,但我需要表現出對用戶的拇指圖像,並有一個微調功能也上傳動作之前。獲得AVFoundationErrorDomain代碼= -11829「試圖generateCGImagesAsynchronouslyForTimes

對於一些記錄文件,同時使用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.} 

我找不出這個問題,任何幫助將不勝感激。謝謝

回答

0

我得到了答案。記錄完成後,我只是增加了一些延遲。

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

對不起,但增加時間取決於解決方案是所有邪惡和無法預料的令人驚訝的大錯誤的根源。我強烈建議您找到更好的解決方案。 – Jan