gpt4 book ai didi

swift - 放大时 avfoundation 录音不起作用

转载 作者:行者123 更新时间:2023-11-28 07:10:50 26 4
gpt4 key购买 nike

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


func beginSessionWithBackCameraAndMic(){



<pre><code> 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()







}
</code></pre>

<p>@IBAction func record(sender: AnyObject) {</p>

<pre><code> var e = NSErrorPointer()

video.lockForConfiguration(e);

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

video.videoZoomFactor = 5


video.unlockForConfiguration()
</code></pre>

<p>var outputpath = NSTemporaryDirectory()+"output.mov";</p>

<pre><code> 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)
</code></pre>

<p>}</p>

<pre><code>func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!) {
</code></pre>

<p>//Here I am doing the necessary works saving works to my internal memory</p>

<p>}</p>

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

如果我只注释这两行

video.activeFormat = video.formats[15] 作为 AVCaptureDeviceFormat

video.videoZoomFactor = 5

录音效果很好。不过,我使用了 SessionPresetHigh。

谁能帮帮我!

谢谢

最佳答案

尝试移动那些故障线

video.lockForConfiguration(e);

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

video.videoZoomFactor = 5

video.unlockForConfiguration()

在您的 beginSessionWithBackCameraAndMic 方法行之前:

self.captureSession.startRunning()

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

关于swift - 放大时 avfoundation 录音不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28551734/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com