如何使用AVCaptureConnections?

问题描述 投票:0回答:2

我是 AVFoundation 的新手,正在尝试实现摄像机。基本上,当您单击按钮时,它会调用

showCamera
方法。它将创建会话,添加音频和视频输入,并添加视频输出。

如何添加

AVCaptureConnection

- (IBAction) showCamera
{
    //Add the camview to the current view ontop of controller
    [[[[[UIApplication sharedApplication] delegate] self] window] addSubview:camView];

    session = [[AVCaptureSession alloc] init];

    //Set preset on session to make recording scale high
    if ([session canSetSessionPreset:AVCaptureSessionPresetHigh]) {
        session.sessionPreset = AVCaptureSessionPresetHigh;
    }
       
    // Add inputs and outputs.
    NSArray *devices = [AVCaptureDevice devices];

    //Print out all devices on phone
    for (AVCaptureDevice *device in devices) 
    {
        
        if ([device hasMediaType:AVMediaTypeVideo]) 
        {
            
            if ([device position] == AVCaptureDevicePositionBack) 
            {
                
                //Add Rear Video input to session
                [self addRearCameraInputToSession:session withDevice:device];
                
            }
            
                        
        } 
        else if ([device hasMediaType:AVMediaTypeAudio]) 
        {
            
            //Add Microphone input to session
            [self addMicrophoneInputToSession:session withDevice:device];
        }
        else
        {
            //Show error that your camera does not have a phone
        }
    }



    //Add movie output
    [self addMovieOutputToSession:session];

    //Construct preview layer
    [self constructPreviewLayerWithSession:session onView:camView];
}
iphone avfoundation avcapturesession
2个回答
3
投票

您无需手动添加 AVCaptureConnections。当您将输入和输出添加到 AVCaptureSession 对象时,系统会自动为您创建连接。引用文档

将输入或输出添加到会话时,会话会贪婪地在所有兼容的捕获输入端口和捕获输出之间形成连接。

除非您需要禁用自动创建的连接之一,或更改

videoMirrored
videoOrientation
属性,否则您根本不必担心它们。


0
投票

看看以下网址...

Apple 的文档:

一篇文章:

使用 AVFoundation 框架 iPhone 进行视频录制?

我想,这会对你有帮助......

© www.soinside.com 2019 - 2024. All rights reserved.