1

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

Haroldo Gondim
  • 7,725
  • 9
  • 43
  • 62
Rajan Kambaliya
  • 157
  • 1
  • 12

2 Answers2

1

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];
Haroldo Gondim
  • 7,725
  • 9
  • 43
  • 62
Mayank Barnwal
  • 123
  • 1
  • 12
  • 1
    It is working but "thumbnailImageAtTime: timeOption:" is deprecated from iOS 7. Thanks for the answer BTW. – Rajan Kambaliya Jan 11 '16 at 10:13
  • I found this: [thumbnailImageAtTime: now deprecated - What's the alternative?](http://stackoverflow.com/questions/19105721/thumbnailimageattime-now-deprecated-whats-the-alternative) and this article: [Getting thumbnail from video url or data](http://www.amaniphoneblog.com/2015/05/getting-thumbnail-from-video-url-or-data-in-IOS.html). – Bista Jan 13 '16 at 06:30
0

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

Haroldo Gondim
  • 7,725
  • 9
  • 43
  • 62
  • It's not working if the video is in app bundle or in document directory. I am getting this error while getting imageRef - "Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x124722f90 {Error Domain=NSOSStatusErrorDomain Code=-12433 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-12433), NSLocalizedDescription=The operation could not be completed}" – Rajan Kambaliya Jan 18 '16 at 10:28
  • This is a new problem. You should search how create the `NSURL` for local files. – Haroldo Gondim Jan 18 '16 at 19:00