2011-11-28 15 views
13

मैं उपयोगकर्ता को वीडियो बनाने और फिर इसे ट्रिम करने के लिए UIImagePicker का उपयोग कर रहा हूं। मुझे उस वीडियो को कई फ्रेम में विभाजित करने की आवश्यकता है और उपयोगकर्ता को उनमें से एक चुनने दें।आईओएस छवियों के रूप में वीडियो फ्रेम निकालने

फ्रेम दिखाने के लिए मुझे संभवतः उन्हें UIImage में परिवर्तित करना होगा। मैं यह कैसे कर सकता हूँ? मुझे AVFoundation का उपयोग करना चाहिए, लेकिन मुझे & फ़्रेम को परिवर्तित करने के तरीके पर एक ट्यूटोरियल नहीं मिला।

क्या मुझे AVFoundation के साथ छवि कैप्चर करना चाहिए? यदि ऐसा है तो मुझे खुद को ट्रिम करने के लिए लागू करना होगा?

उत्तर

12

मुझे लगता है कि इस प्रश्न का उत्तर वह है जिसे आप ढूंढ रहे हैं।

iPhone Read UIimage (frames) from video with AVFoundation

स्वीकृत उत्तर द्वारा निर्दिष्ट 2 विधियां हैं। आप अपनी आवश्यकता के अनुसार किसी एक का उपयोग कर सकते हैं।

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) कोड है

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."); 
     } 
    }]; 
} 
संबंधित मुद्दे