0

Iam trying to capture video using front camera in ios and convert that into sequence of images I am trying to use avassetimagegenerator for that . Iam new to AV Foundation please help me in this , thanks .

naveen
  • 69
  • 7

1 Answers1

0

First present an UIImagePickerController

- (void)presentVideoPicker {
    UIImagePickerController *anImagePicker = [[UIImagePickerController alloc] init];
    anImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    anImagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    anImagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie, nil];
    anImagePicker.allowsEditing = YES;
    anImagePicker.delegate = self;

    UIPopoverController *aPopoverController = [[[UIPopoverController alloc] initWithContentViewController:anImagePicker] autorelease];
    [aPopoverController presentPopoverFromRect:self.view.frame inView:[[self view] window]
                          permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

Capture the Video in UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *aMediaType = [info objectForKey:UIImagePickerControllerMediaType];

    if ([aMediaType isEqualToString:(NSString *)kUTTypeMovie]) {
        NSURL *aVideoURL = [info objectForKey:UIImagePickerControllerMediaURL];
        [self readMovie:aVideoURL];

        // If you want the Duration fo the Video, Use this
        AVPlayerItem *aPlayerItem = [AVPlayerItem playerItemWithURL:aVideoURL];
        CMTime aDuration = aPlayerItem.duration;
        float anInSeconds = CMTimeGetSeconds(aDuration);
        NSInteger aDuration = nearbyintf(anInSeconds);
    }
}

Now code for the Method you called in the Delegate - (void) readMovie:(NSURL *)url

Refer this link: http://www.7twenty7.com/blog/2010/11/video-processing-with-av-foundation

...

Once you generate the CVImageBuffer for an Image,

Refer how to convert a CVImageBufferRef to UIImage

to convert it to UIImage

Community
  • 1
  • 1
Roshit
  • 1,589
  • 1
  • 15
  • 37