我正在从存储在文档目录中的录制视频生成缩略图,该视频不能超过 1 分钟。直到录制时间一切正常。当我尝试从录制的视频中生成缩略图时一无所获。我使用了两种方法
通过使用 MPMoviePlayerController
-(void)generateThumbnail:(NSURL*)assetURL{ if(assetURL){ MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:assetURL]; UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame]; //AT THIS POINT AS I CHECK IT THIS thumbnail contains 0X000000 player = nil; if (thumbnail) { //will use that image to further } else { //here wil doing some intimation } } }
如上方法完成执行得到这些日志
自动播放:启用自动播放自动播放:可能跟上或满缓冲区:0 [MPAVController] 自动播放:跳过自动播放,没有足够的缓冲跟上。[MPAVController] 自动播放:启用自动播放 [MPAVController] 自动播放:启用自动播放 [MPAVController] 自动播放:跳过自动播放,禁用(当前项目:0,播放器上:1) [MPAVController] 自动播放:启用自动播放[MPAVController] 自动播放:跳过自动播放,禁用(当前项目:0,播放器:1)
通过使用 AVAssetImageGenerator
-(void)genrateThumbnailImageFromAsset:(AVAsset*)_assetObject size:(CGSize)size forTime:(CMTime)thumbTime { __weak typeof(self) wself = self; __block UIImage * thumbNailImage = nil; AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:_assetObject]; generator.appliesPreferredTrackTransform=TRUE; AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error) { switch (result) { case AVAssetImageGeneratorSucceeded:{ /*get the generated image*/ thumbNailImage=[UIImage imageWithCGImage:im]; // We finished updating the image. Set the visual UI button to the uploaded image if (thumbNailImage) { //using accordingly } else { //using accordingly } } break; case AVAssetImageGeneratorFailed:{ //using accordingly NSLog(@"%@",[error localizedDescription]); } break; case AVAssetImageGeneratorCancelled:{ //using accordingly NSLog(@"%@",[error localizedDescription]); } break; default: break; } }; generator.maximumSize = size; [generator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:thumbTime]] completionHandler:handler]; }
By Above 一无所获....仍在寻找相同的东西。