Reputation: 848
I want to fetch video thumbnail from URL instead using MPMoviePlayerController
and AVAssetImageGenerator
. Because these have some issue. Issue I have already asked,
1st one is : AVAssetImageGenerator not working properly, I am unable to fetch thumbnail of video from URL
I have no idea how to do it. Any suggestion will be great. Thank in advance !!!
Upvotes: 0
Views: 823
Reputation: 339
All you need is to put into comment below your URL and self.imageView.image = FrameImage;
Anyway.
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];
Upvotes: 1
Reputation: 339
Try this one.
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];
Upvotes: 0