美文网首页
swift WebRTC 屏幕录制帧率低

swift WebRTC 屏幕录制帧率低

作者: 简化 | 来源:发表于2020-12-09 10:44 被阅读0次

    我的帧率低是因为时间戳设置为1s了,需要手动设置一下偏移量

        // MARK: 屏幕共享
        func startSharingScreen(renderer: RTCVideoRenderer) {
            guard let videoSource = screenCapture else {
                return
            }
            var tempTimeCount = 0
            let recoder = RPScreenRecorder.shared()
            recoder.startCapture { (buffer, type, error) in
                switch (type){
                case .video:
                    let pixelBuffer:CVPixelBuffer = CMSampleBufferGetImageBuffer(buffer)!
                    let rtcPixelBuffer = RTCCVPixelBuffer(pixelBuffer: pixelBuffer)
                    let timeStampNs = UInt64(CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(buffer)) + Double(tempTimeCount)) * NSEC_PER_SEC
                    let videoFrame = RTCVideoFrame(buffer: rtcPixelBuffer, rotation: ._0, timeStampNs: Int64(timeStampNs))
                    videoSource.capturer(self.videoCapturer!, didCapture: videoFrame)
                    tempTimeCount += 1
                    //print(timeStampNs)
                    break
                case .audioApp:
                    break
                case .audioMic:
                    break
                @unknown default:
                    break
                }
            } completionHandler: { (error) in
                if (error != nil){
                    print("startSceenCapture completionHandler 出错\(error!)")
                }
            }
            
            self.localVideoTrack?.add(renderer)
        }
    

    相关文章

      网友评论

          本文标题:swift WebRTC 屏幕录制帧率低

          本文链接:https://www.haomeiwen.com/subject/pmthgktx.html