【问题标题】:avfoundation recording is not working while zoomed缩放时 avfoundation 录制不起作用
【发布时间】:2015-02-16 22:50:35
【问题描述】:

我正在编写一个相机应用程序,我试图在 avfoundation 上实现缩放。我的代码在这里

func beginSessionWithBackCameraAndMic(){

    captureSession.sessionPreset = AVCaptureSessionPresetHigh

    captureSession.beginConfiguration()

    var err:NSError?

    videoInput = AVCaptureDeviceInput(device: self.cameraWithPosition(AVCaptureDevicePosition.Back), error: &err)

    if(self.captureSession.canAddInput(videoInput)){
        self.captureSession.addInput(videoInput);
    }

    audioInput = AVCaptureDeviceInput(device: audio, error: &err)

    if(self.captureSession.canAddInput(audioInput)){
        self.captureSession.addInput(audioInput);
    }

    if (captureSession.canAddOutput(movieFileOutput)){
        captureSession.addOutput(movieFileOutput)
    }



    var captureconneciton = movieFileOutput.connectionWithMediaType(AVMediaTypeVideo)

    var orientation = getOrientation()

    captureconneciton.videoOrientation = orientation



    previewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession)

    previewLayer?.connection.videoOrientation = orientation

    previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill

    previewLayer?.frame = self.v.bounds

    self.v.layer.addSublayer(previewLayer)



    captureSession.commitConfiguration()

    self.captureSession.startRunning()







}

@IBAction func 记录(发送者:AnyObject){

    var e = NSErrorPointer()

    video.lockForConfiguration(e);

    video.activeFormat = video.formats[15] as AVCaptureDeviceFormat

    video.videoZoomFactor = 5


    video.unlockForConfiguration()

var outputpath = NSTemporaryDirectory()+"output.mov";

        var outputURL = NSURL(fileURLWithPath: outputpath)

        var fileManager = NSFileManager.defaultManager()

        if fileManager.fileExistsAtPath(outputpath){
            var error:NSError? = nil;
            if (fileManager.removeItemAtPath(outputpath, error:&error) == false)
            {
                print("error saving temp file")
            }
        }

        movieFileOutput.startRecordingToOutputFileURL(outputURL, recordingDelegate: self)

}

func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!) {

//这里我正在做必要的工作,将工作保存到我的内存中

}

在录制功能时,我更改了支持缩放的活动视频格式,但是当我遇到这样的崩溃时 2015-02-17 04:16:22.308 Ourdrum[1379:159045] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - no active/enabled connections.'

如果我只是评论这两行

video.activeFormat = video.formats[15] as AVCaptureDeviceFormat

video.videoZoomFactor = 5

录音工作正常。不过我用过 SessionPresetHigh。

有人可以帮忙吗!

谢谢

【问题讨论】:

  • 嘿 :) 同样的问题,你找到答案了吗?

标签: swift ios8 avfoundation ios8.1


【解决方案1】:

尝试移动那些麻烦线

video.lockForConfiguration(e);

video.activeFormat = video.formats[15] as AVCaptureDeviceFormat

video.videoZoomFactor = 5

video.unlockForConfiguration()

在你的 beginSessionWithBackCameraAndMic 方法的行之前:

self.captureSession.startRunning()

如果您锁定配置,您可以随时更改缩放系数,但我认为您必须在启动之前设置视频格式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 2014-10-25
    相关资源
    最近更新 更多