Ios – MPMoviePlayerController generate thumbnail of local video file and store it

iosipadmpmovieplayercontrollerobjective cthumbnails

I'm making an app that downloads movies from the server and stores them localy in the NSDocumentDirectory.

This works fine.

I want to add a thumbnail generated from each movie in front of the name in each cell.

My problem:

How can I generate a thumbnail from a movie after it is downloaded (so instantly, without having to play the movie first)? I want to store the thumbnails with the same name of the movie as a jpg in the NSDocumentDirectory.

My guess

-download movie and store it in NSDocumentDirectory (works)

-somehow load the movie in the MPMoviePlayerController's memory (don't know how)

-when loaded in memory, generate thumbnail with thumbnailImageAtTime (MPMovieTimeOptionNearestKeyFrame) (should work)

-store it (should work)

If anyone could help me…

Thanks

Best Answer

#import <MediaPlayer/MediaPlayer.h>   


-(UIImage*)getFirstFrameFromVideoFile:(NSString*)sourceFilePath {
NSURL *videoURL = [NSURL fileURLWithPath:sourceFilePath];

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
//Player autoplays audio on init
[player stop];
[player release];
return thumbnail;
}

Other tasks you know already.

Related Topic