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 .

4

1 回答 1

0

首先呈现一个 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];
}

在 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);
    }
}

现在为您在委托中调用的方法编写代码- (void) readMovie:(NSURL *)url

参考这个链接: http ://www.7twenty7.com/blog/2010/11/video-processing-with-av-foundation

...

为图像生成 CVImageBuffer 后,

请参阅 如何将 CVImageBufferRef 转换为 UIImage

将其转换为 UIImage

于 2013-05-16T09:34:05.323 回答