2011-11-28 8 views
13

私はUIImagePickerを使用して、ビデオを作成してトリミングすることができます。私は、そのビデオを複数のフレームに分割し、ユーザーがそれらのフレームの1つを選択させる必要があります。iOSビデオフレームを画像として抽出する

フレームを表示するために、おそらくそれらをUIImageに変換する必要があります。これどうやってするの?私はAVFoundationを使用する必要がありますが、&のフレームを変換する方法に関するチュートリアルを見つけることができませんでした。

AVFoundationで画像をキャプチャする必要がありますか?もしそうなら、自分でトリミングを実装する必要がありますか?

答えて

0

また、AVFoundationに基づいてlib VideoBufferReader(see on GitHub)を使用することもできます。ここ

6

は、のviewDidLoad

videoUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"VfE_html5" ofType:@"mp4"]]; 
    [self createImage:5]; // 5 is frame per second (FPS) you can change FPS as per your requirement. 
ビデオ

1)インポート

#import <Photos/Photos.h> 

2)からFPS画像を取得するためのコードであります

3)

-(void)createImage:(int)withFPS { 
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoUrl options:nil]; 
    AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset]; 
    generator.requestedTimeToleranceAfter = kCMTimeZero; 
    generator.requestedTimeToleranceBefore = kCMTimeZero; 

    for (Float64 i = 0; i < CMTimeGetSeconds(asset.duration) * withFPS ; i++){ 
     @autoreleasepool { 
      CMTime time = CMTimeMake(i, withFPS); 
      NSError *err; 
      CMTime actualTime; 
      CGImageRef image = [generator copyCGImageAtTime:time actualTime:&actualTime error:&err]; 
      UIImage *generatedImage = [[UIImage alloc] initWithCGImage:image]; 
      [self savePhotoToAlbum: generatedImage]; // Saves the image on document directory and not memory 
      CGImageRelease(image); 
     } 
    } 
} 

-(void)savePhotoToAlbum:(UIImage*)imageToSave { 

    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ 
     PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:imageToSave]; 
    } completionHandler:^(BOOL success, NSError *error) { 
     if (success) { 
      NSLog(@"sucess."); 
     } 
     else { 
      NSLog(@"fail."); 
     } 
    }]; 
} 
を に関する機能します
関連する問題