Objective-c,有没有办法使用MPMoviePlayerController和AVAssetImageGenerator从URL获取视频缩略图?

时间:2015-09-07 06:22:58

标签: ios objective-c iphone mpmovieplayercontroller video-thumbnails

我想使用MPMoviePlayerControllerAVAssetImageGenerator从网址获取视频缩略图。因为这些有一些问题。问题我已经问过了,

第一个是: AVAssetImageGenerator not working properly, I am unable to fetch thumbnail of video from URL

,第二名是: https://stackoverflow.com/questions/32431311/mpmovieplayercontroller-not-fetching-thumbnail-of-video-from-url-properly

我不知道该怎么做。任何建议都会很棒。提前谢谢!!!

2 个答案:

答案 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];