Cover by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

9.7. Capturing Thumbnails From a Video File

Problem

You are playing a video file using an instance of the MPMoviePlayerController class and would like to capture a screenshot from the movie at a certain time.

Solution

Use the requestThumbnailImagesAtTimes:timeOption: instance method of MPMoviePlayerController like so:

/* Capture the frame at the third second into the movie */
NSNumber *thirdSecondThumbnail = [NSNumber numberWithFloat:3.0f];

/* We can ask to capture as many frames as we 
 want. But for now, we are just asking to capture one frame */
NSArray  *requestedThumbnails = 
[NSArray arrayWithObject:thirdSecondThumbnail];

/* Ask the movie player to capture this frame for us */
[self.moviePlayer 
 requestThumbnailImagesAtTimes:requestedThumbnails
 timeOption:MPMovieTimeOptionExact];

Discussion

An instance of MPMoviePlayerController is able to capture thumbnails from the currently playing movie, synchronously and asynchronously. In this recipe, we are going to focus on asynchronous image capture for this class.

We can use the requestThumbnailImagesAtTimes:timeOption: instance method of MPMoviePlayerController to asynchronously access thumbnails. When I say “asynchronously,” I mean that during the time the thumbnail is being captured and reported to your designated object (as we will soon see), the movie player will continue its work and will not block the playback. We must observe the MPMoviePlayerThumbnailImageRequestDidFinishNotification notification message the movie player sends to the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required