3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iOS 動画からサムネイル画像を取得

Last updated at Posted at 2016-12-10

複数の動画ファイルを画面に一覧で表示させる時にサムネイル画像で表示させたい場合がありましたのでそのコードを下記に記載します。

1.AVFoundation.frameworkをプロジェクトに追加してください

2.下記のコードで動画からフレームを取得してそれを画像にします

xxxxx.m
NSURL *url = サムネイルを取得したい動画ファイルのパス;

NSDictionary *assetOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVAsset *localAsset = [AVURLAsset URLAssetWithURL:url options:assetOptions];
AVAssetImageGenerator *imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:localAsset];

CGImageRef thumbImage = [imageGenerator copyCGImageAtTime:kCMTimeZero actualTime:NULL error:&error];
UIImage *thumbnailImg = [UIImage imageWithCGImage:thumbImage];

3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?