Bavan
Bavan

Reputation: 1040

Why do I get Slower Frame Rate while Capturing Screen in OSX?

I am referring to the AVScreenShack example.I even got rid of the Preview feature to see if it improves. But, the Frame Skipping is very visible. I thought my computer is not powerful enough, but when I used QuickTime Player to record the Screen, the Video was silky smooth.

How can I improve the following code to get a high fps output?

func startRecording(){
        mSession = AVCaptureSession()
        mSession?.sessionPreset = AVCaptureSessionPresetHigh
        let displayId : CGDirectDisplayID = CGMainDisplayID()

        let session : AVCaptureSession
        if mSession != nil {
            session = mSession!
        }else{
            return
        }

        let input : AVCaptureScreenInput = AVCaptureScreenInput(displayID: displayId)
        input.minFrameDuration = CMTimeMake(1, 35)
        if let rect = delegate?.cropRect() {
            input.cropRect = rect
        }

        if session.canAddInput(input) {
            session.addInput(input)
        }else{
            return
        }

        mMovieFileOutput = AVCaptureMovieFileOutput()

        if session.canAddOutput(mMovieFileOutput) {
            session.addOutput(mMovieFileOutput!)
        }

        mSession?.startRunning()
        mMovieFileOutput?.movieFragmentInterval = kCMTimeInvalid
        mMovieFileOutput?.startRecording(toOutputFileURL: URL(fileURLWithPath:"/Users/Tester/Desktop/capture.mov"), recordingDelegate: self)

    }

Upvotes: 0

Views: 658

Answers (1)

Gordon Childs
Gordon Childs

Reputation: 36139

You can get a higher framerate by lowering the minimum frame duration:

input.minFrameDuration = CMTimeMake(1, 60)

N.B. this doesn't guarantee a higher framerate, but it allows one.

Upvotes: 1

Related Questions