Extract thumbnail from video url

I have to extract a thumbnail from a video (from url) and I use this code:

NSString *stringUrl = video.stringurl;
NSURL *url = [NSURL URLWithString:stringUrl];

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
[imageGenerator setRequestedTimeToleranceBefore:kCMTimeZero];
[imageGenerator setRequestedTimeToleranceAfter:kCMTimeZero];

CGImageRef imageRef = [imageGenerator copyCGImageAtTime:playerCurrentTime actualTime:&actualtime error:&error];
UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];


But sometime I have an error with copyCGImageAtTime and the thumbnail is not generated. The error is: Error save image Error Domain=AVFoundationErrorDomain Code=-11800 “The operation could not be completed”(OSStatus error -12792.)”, NSLocalizedFailureReason=An unknown error occurred (-12792)}

Here is the link which I have read a solution but if a use fileURLWithPath: instead of URLWithString: the method add to the end of the url an “– file://localhost/” that invalidates the url. So I don’t know what I can do.

Get thumbnail image of video from video url

Is it possible to get the thumbnail image from a video Url? I need to thumbnails of videos in a list view.

Create thumbnail from a video url in IPhone SDK

Hy everybody I am trying to acquire a thumbnail from a video url. The video is a stream (HLS) with the m3u8 format. I’ve already tried requestThumbnailImagesAtTimes from the MPMoviePlayerController, b

Extract thumbnail images from a video – jQuery plugin?

I’m using jwplayer to display videos on a website. I’m looking for a jQuery plugin that can extract thumbnail images from these videos because uploaders upload only the videos, no thumbnails. My aim i

How to extract images from a video?

can anyone tell me how to extract images from a video? what i ve tried till now is i ve follow these: Getting iPhone video thumbnails Getting thumbnail from a video url or data in IPhone SDK How do I

FFmpeg: Given a specific frame I need to extract a thumbnail from a video using FFmpeg

Given a specific frame I need to extract an image (a thumbnail) from a video using FFmpeg. E.g. I can do: ffmpeg -i test.mp4 -ss 00:01:14.35 -vframes 1 out2.png I can extract an image from a specific

Extract flicker video thumbnail

I have to make a video gallery , where users will upload flicker video link. I need thumbnails of video. how can i do it using javascript/php ?

Getting thumbnail from video url and loading on gridview very slow

I am getting the list of video url from the sdcard and passing to the adapter. In adapter, creating the thumbnail bitmap from the url of video. It became very slow to load the gridview and scrolling a

Android – Display a video thumbnail from a URL

I need to display a video thumbnail based to a URL into an ImageView view child of my ListView items, i have found this post but not worked. Result Code thumb_image.setImageBitmap(new LoadVideoThumb

How can i get thumbnail of video from Remote URL for android 4.0 and above?

Actually, I want to show a thumbnail of video from Video URL and show it in ImageView and then on click of ImageView the VideoView shows video in another activity. So ultimately My problem is that, i

Codeigniter – Getting “thumbnail_url” from youtube video JSON response [closed]

I am trying to save a thumbnail img URL from a youtube video through its JSON response. The user submits a youtube link through a form first. Controller: $data[‘video_thumb’] = $this->gallery_mo


on one of my app i’ve captured an image from the video url like this:

MPMoviePlayerController *player = [[[MPMoviePlayerController alloc] initWithContentURL:videoURL]autorelease];
UIImage  *thumbnail = [player thumbnailImageAtTime:0.0 timeOption:MPMovieTimeOptionNearestKeyFrame];

just passing the url object as videoURL and with the use of MPMoviePlayerController i successfully able to have the image all the time. hope you too will be able to do this with this simple code

If you are using MPMoviePlayerController then you can use this code to generate thumbnail from video URL.

NSString *stringUrl = video.stringurl;
NSURL *url = [NSURL URLWithString:stringUrl];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];

But, using this code, player will start autoplaying audio. So, you have to stop the player with this code :

//Player autoplays audio on init
[player stop];

Update :

Error save image Error Domain=AVFoundationErrorDomain Code=-11800 “The operation could not be completed”(OSStatus error -12792.)”, NSLocalizedFailureReason=An unknown error occurred (-12792)}

The Error is probably due to use of URLWithString. I think you should use -fileURLWithPath instead of URLWithString.

Sample Code :

NSString *stringUrl = video.stringurl;
NSURL *vidURL = [NSURL fileURLWithPath:stringUrl];

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:vidURL options:nil];
AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];

NSError *err = NULL;
CMTime time = CMTimeMake(1, 60);

CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *thumbnail = [UIImage imageWithCGImage:imgRef];

If you are using AVPlayer, you can get the thumbnail like this:

AVAsset *asset = [AVAsset assetWithURL:sourceURL];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
CMTime time = CMTimeMake(1, 1);
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];
UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);  // CGImageRef won't be released by ARC

I’m trying too grab a screenshot from an HLS variable bitrate stream. I.E. M3U8, and none of the methods provided here worked for me.

I did succeed at the end. First you need to attach an AVPlayerItemVideoOutput to your player:

 self.playerAV = [AVPlayer playerWithURL:localURL];

    NSDictionary* settings = @{ (id)kCVPixelBufferPixelFormatTypeKey : [NSNumber numberWithInt:kCVPixelFormatType_32BGRA] };
    AVPlayerItemVideoOutput* output = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:settings];
    [self.playerAV.currentItem addOutput:output];

Now when you wanna grab the screenshot:

  CVPixelBufferRef pixelBuffer = [output copyPixelBufferForItemTime:player.currentTime itemTimeForDisplay:nil];
            CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];

            CIContext *temporaryContext = [CIContext contextWithOptions:nil];
            CGImageRef videoImage = [temporaryContext
                                     fromRect:CGRectMake(0, 0,

            image = [UIImage imageWithCGImage:videoImage];
            image = [image cropImageToSize:maxSize withProportionDiffLargerThan:IMAGE_PROPORTION_DIFF];

            if ( videoImage )

AVAssetImageGenerator does not work for HSL videos.

I was able to get an image from the HSL video using the sample code below.

Sample code :

CMTime currentTime = _player.currentItem.currentTime;
CVPixelBufferRef buffer = [_videoOutput copyPixelBufferForItemTime:currentTime itemTimeForDisplay:nil];
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:buffer];
UIImage *thumbImage = [UIImage imageWithCIImage:ciImage];