I am Generating the thumbnail from the recorded video which is stored in the documents directory that video can't not be more than to the 1 minute. till the recording time everything works properly.as i try to generate the thumbnail from that recorded video got nothing.i have used the two way for the same
By using the 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
}
}
}
As Above method finish with the execution got these logs
Autoplay: Enabling autoplay Autoplay: Likely to keep up or full buffer: 0 [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up. [MPAVController] Autoplay: Enabling autoplay [MPAVController] Autoplay: Enabling autoplay [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1) [MPAVController] Autoplay: Enabling autoplay[MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player:1)
By using 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 got nothing .... still looking for the same.
Finally got the way, actually i have mistakenly placed the wrong method for creating the URL of that recorded video
I was using urlWithString
instead of fileURLWithPath
as i used fileURLWithPath
everything working fine.