Rajan Kambaliya
Rajan Kambaliya

Reputation: 157

How do I get NSArray of images from a video? Vice-versa is possible

It is possible that I can play video from NSArray of images. But how can I get NSArray of images from a video?

Upvotes: 1

Views: 126

Answers (2)

Mayank Barnwal
Mayank Barnwal

Reputation: 123

You can use this code to make image from Video and later you can save those image in a array

UIImage *singleFrameImage = [self.theMoviePlayer 
                              thumbnailImageAtTime:i 
                                        timeOption:MPMovieTimeOptionExact];

Upvotes: 1

Haroldo Gondim
Haroldo Gondim

Reputation: 7993

To get a image from your video use this sample.

First import AVFoundation

#import <AVFoundation/AVFoundation.h>

Create the NSURL from your video.

NSString *videoUrl = @"http://download.wavetlan.com/SVV/Media/HTTP/MP4/ConvertedFiles/Media-Convert/Unsupported/test7.mp4";
NSURL *url = [NSURL URLWithString:videoUrl];

Prepare the asset.

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generate.appliesPreferredTrackTransform = YES;

Select the time to cut: e.g. In second 2 for 1 second.

CMTime time = CMTimeMake(2, 1);

Get the ImageRefference and the Thumbnail.

NSError *error = nil;
CGImageRef imageRef = [generate copyCGImageAtTime:time actualTime:nil error:&error];

UIImage *thumbnail = [[UIImage alloc] initWithCGImage:imageRef];

Set your image to some UIImageView .

[self.imageView setImage:thumbnail];

The Sample shows this image

Upvotes: 0

Related Questions