在 iPhone 上捕获视频和图片

4
我正在使用ImagePickerController进行视频捕捉,同时需要将所捕捉的视频保存为图像。
因此,我选择了AVCaptureSession来捕获图像。但我无法同时运行AVCaptureSession和ImagePickerController。因此,我需要将ImagePickerController作为输入提供给AVCaptureSession。
但我不知道如何做到这一点。请帮助我,并为我提供正确的建议。

请参考此链接:https://dev59.com/aVTTa4cB1Zd3GeqPsGYU - visakh7
请问您能否给我推荐其他链接,其中有更详细的代码呢?谢谢。 - Ganesh
4个回答

3

第一个链接什么也没有,就像拍照一样,而第二个链接已经由你提供了。我使用ffmpeg将视频转换为图像。但是它最多需要2.15分钟才能将一分钟的视频转换。您有任何关于如何提高转换速度的想法吗?那将是非常有帮助的... - Ganesh

2

我遇到了同样的问题。我在处理图像和视频方面进行了工作,并使用以下代码来捕获图像:

- (void) snapImage: (id) sendern
{
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    ipc.sourceType =  UIImagePickerControllerSourceTypeCamera;
    ipc.delegate = self;
    ipc.allowsImageEditing = YES;
    [self presentModalViewController:ipc animated:YES]; 

}

我使用以下代码进行视频录制:

- (void) recordVideo: (id) sender
{
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    ipc.sourceType =  UIImagePickerControllerSourceTypeCamera;
    ipc.delegate = self;
    ipc.allowsEditing = YES;
    ipc.videoQuality = UIImagePickerControllerQualityTypeMedium;
    ipc.videoMaximumDuration = 30.0f; // 30 seconds
    ipc.mediaTypes = [NSArray arrayWithObject:@"public.movie"];
    // ipc.mediaTypes = [NSArray arrayWithObjects:@"public.movie", @"public.image", nil];
    [self presentModalViewController:ipc animated:YES]; 
}

希望这些代码片段能对你有所帮助。

1
    - (IBAction) useCamera: (id)sender
    {
        if ([UIImagePickerController isSourceTypeAvailable:
             UIImagePickerControllerSourceTypeCamera])
        {
            UIImagePickerController *imagePicker =
            [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.sourceType =
            UIImagePickerControllerSourceTypeCamera;
            imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                      (NSString *) kUTTypeImage,
                                      nil];
            imagePicker.allowsEditing = NO;
            [self presentModalViewController:imagePicker
                                    animated:YES];
            newMedia = YES;
        }
    }

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self.popoverController dismissPopoverAnimated:true];

    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    [self dismissModalViewControllerAnimated:YES];
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) 
    {
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    imageView.image = image;
        if (newMedia)
            UIImageWriteToSavedPhotosAlbum(image, self,  
                                           @selector(image:finishedSavingWithError:contextInfo:),nil);
    }

}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
 contextInfo:(void *)contextInfo
{
    if (error) 
    {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"Save failed"
                              message: @"Failed to save image"
                              delegate: self
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alert show];

    }
}

0

我想要做的是捕获视频并将视频帧作为图像捕获。我使用ffmpeg将视频转换为图像,但这需要更多时间。我需要缩短时间。所有专家都建议使用AVAssetReader将视频转换为图像。你能否请给我发送转换视频为图像的链接或代码(可以更快地完成工作)...拜托了... - Ganesh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接