当前位置:  开发笔记 > 编程语言 > 正文

视频录制没有音频?

如何解决《视频录制没有音频?》经验,为你挑选了1个好方法。

我制作了一个成功的视频录制节目,但它没有音频?我该怎么做才能解决这个问题?我已经在我的设置中正确设置了音频权限info.plist.我正在使用AVCaptureFileOutputRecordingDelegate.

 override func viewWillAppear(_ animated: Bool) {
      let deviceDiscoverySession = AVCaptureDeviceDiscoverySession(deviceTypes: [AVCaptureDeviceType.builtInDuoCamera, AVCaptureDeviceType.builtInTelephotoCamera,AVCaptureDeviceType.builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: AVCaptureDevicePosition.back)

    for device in (deviceDiscoverySession?.devices)!{
        if(device.position == AVCaptureDevicePosition.back){

            do{
                let input = try AVCaptureDeviceInput(device: device )

                if captureSession.canAddInput(input){

                    captureSession.addInput(input)

                }

               // sessionOutput.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString) : NSNumber(value: kCVPixelFormatType_420YpCbCr8BiPlanarFullRange as UInt32)]

                sessionOutput.alwaysDiscardsLateVideoFrames = true

                if(captureSession.canAddOutput(sessionOutput) == true){
                    captureSession.addOutput(sessionOutput)

                    let previewLayer: AVCaptureVideoPreviewLayer = {
                        let preview =  AVCaptureVideoPreviewLayer(session: self.captureSession)
                        preview?.bounds = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)
                        preview?.position = CGPoint(x: self.view.bounds.midX, y: self.view.bounds.midY)
                        preview?.videoGravity = AVLayerVideoGravityResize
                        return preview!
                    }()

                    view.layer.insertSublayer(previewLayer, at: 0)

                    output = AVCaptureMovieFileOutput()
                    let maxDuration = CMTimeMakeWithSeconds(180, 30)
                    output.maxRecordedDuration = maxDuration
                    captureSession.addOutput(output)



                }

                captureSession.commitConfiguration()

            }

            catch{
                print("Error")
            }


        }

    }

我已经尝试过这里发布的解决方案,但它所做的一切都搞砸了我已经使用相机的工作.任何指导表示赞赏!



1> Florent Mori..:

简单的步骤,实现你想要的:

    获取视频捕获设备(AVMediaTypeVideo)

    获取音频捕获设备(AVMediaTypeAudio)

    创建视频输入(带视频设备的AVCaptureDeviceInput)

    创建音频输入(带音频设备的AVCaptureDeviceInput)

    通过beginConfiguration()配置捕获会话(AVCaptureSession)

    添加输入以通过addInput()捕获会话

    通过commitConfiguration()提交配置

推荐阅读
李桂平2402851397
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有