我想使用MPMoviePlayerController
和AVAssetImageGenerator
从网址获取视频缩略图。因为这些有一些问题。问题我已经问过了,
第一个是: AVAssetImageGenerator not working properly, I am unable to fetch thumbnail of video from URL
我不知道该怎么做。任何建议都会很棒。提前谢谢!!!
答案 0 :(得分:1)
您只需在网址和self.imageView.image = FrameImage;
反正。
NSString *str=@"https://scontent.cdninstagram.com/hphotos-xfa1/t50.2886-16/11719145_918467924880620_816495633_n.mp4";
NSURL *url=[[NSURL alloc]initWithString:str];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
NSError *error = NULL;
CMTime thumbTime = CMTimeMakeWithSeconds(0,30);
CGImageRef refImg = [generator copyCGImageAtTime:thumbTime actualTime:NULL error:&error];
if(error) {
NSLog(@"%@", [error localizedDescription]);
}
UIImage *FrameImage= [[UIImage alloc] initWithCGImage:refImg];
[self.imageView setImage:FrameImage];
答案 1 :(得分:0)
试试这个。
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:@"[video URL]"] options:nil];
AVAssetImageGenerator *generateImg = [[AVAssetImageGenerator alloc] initWithAsset:asset];
NSError *error = NULL;
CMTime time = CMTimeMake(1, 65);
CGImageRef refImg = [generateImg copyCGImageAtTime:time actualTime:NULL error:&error];
NSLog(@"error==%@, Refimage==%@", error, refImg);
UIImage *FrameImage= [[UIImage alloc] initWithCGImage:refImg];