You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.5 KiB
41 lines
1.5 KiB
![]()
2 years ago
|
//
|
||
|
// XHMessageVideoConverPhotoFactory.m
|
||
|
// MessageDisplayExample
|
||
|
//
|
||
|
// Created by HUAJIE-1 on 14-5-9.
|
||
|
// Copyright (c) 2014年 曾宪华 开发团队(http://iyilunba.com ) 本人QQ:543413507 本人QQ群(142557668). All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "XHMessageVideoConverPhotoFactory.h"
|
||
|
#import <AVFoundation/AVAsset.h>
|
||
|
#import <AVFoundation/AVAssetImageGenerator.h>
|
||
|
#import "XHMacro.h"
|
||
|
|
||
|
@implementation XHMessageVideoConverPhotoFactory
|
||
|
|
||
|
+ (UIImage *)videoConverPhotoWithVideoPath:(NSString *)videoPath {
|
||
|
if (!videoPath)
|
||
|
return nil;
|
||
|
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:videoPath] options:nil];
|
||
|
NSParameterAssert(asset);
|
||
|
AVAssetImageGenerator *assetImageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
|
||
|
assetImageGenerator.appliesPreferredTrackTransform = YES;
|
||
|
assetImageGenerator.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;
|
||
|
|
||
|
CGImageRef thumbnailImageRef = NULL;
|
||
|
CFTimeInterval thumbnailImageTime = 0;
|
||
|
NSError *thumbnailImageGenerationError = nil;
|
||
|
thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60) actualTime:NULL error:&thumbnailImageGenerationError];
|
||
|
|
||
|
if (!thumbnailImageRef)
|
||
|
DLog(@"thumbnailImageGenerationError %@", thumbnailImageGenerationError);
|
||
|
|
||
|
UIImage *thumbnailImage = thumbnailImageRef ? [[UIImage alloc] initWithCGImage:thumbnailImageRef] : nil;
|
||
|
|
||
|
CGImageRelease(thumbnailImageRef);
|
||
|
|
||
|
return thumbnailImage;
|
||
|
}
|
||
|
|
||
|
@end
|