swift WebRTC 屏幕录制帧率低

我的帧率低是因为时间戳设置为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 屏幕录制帧率低)