2

I created a screen recording app.

Before appending the buffer to the writer, I check if the isReadyForMoreMediaData is true.

But sometimes it will constantly return false and won’t become true until I call markAsFinished

I have no idea how to fix this.

let videoCompressionProperties = [

    AVVideoAverageBitRateKey: resolution.dataRate

]

let videoSettings: [String: Any] = [

    AVVideoCodecKey:                  encoding,

    AVVideoWidthKey:                  resolution.size.width,

    AVVideoHeightKey:                 resolution.size.height,

    AVVideoCompressionPropertiesKey:  videoCompressionProperties,

    AVVideoScalingModeKey:            AVVideoScalingModeResizeAspect,

    AVVideoColorPropertiesKey:        colorSpace.properties.dictionary,

]

videoInput = AVAssetWriterInput(mediaType: .video, outputSettings: videoSettings)
videoInput?.expectsMediaDataInRealTime = true

Append buffers:

if videoInput?.isReadyForMoreMediaData == true {
    guard buffer.imageBuffer != nil else { return }
    processQueue.async { [self] in
        videoInput?.append(buffer)
    }
} else {
    logger.warning("Dropped a frame.")
    // I found this in stackoverflow. But no effect
    // RunLoop.current.run(until: .now.addingTimeInterval(0.1))
    // The code below will notify me when the bug occurrs.
    // errorFixedPublisher.send()
    // if !self.errorOccured {
    //     self.errorOccured = true
    //     let center = UNUserNotificationCenter.current()
    //     let content = UNMutableNotificationContent()
    //     content.sound = UNNotificationSound.defaultCritical
    //     content.badge = 1
    //     content.body = "Dropping frames at \(Date.now.formatted(date: .omitted, time: .standard))"
    //     let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
    //     let req = UNNotificationRequest(identifier: "ASWRI_ERR", content: content, trigger: trigger)
    //     center.add(req)
    }
}

Any idea on it?? Please help me.

Have a good day!

  • Is it happening only in iOS 16? Also, do you have issues with the audio of the video as well? – Mehmet Baykar Oct 26 '22 at 08:46
  • Not in iOS 16, it's in macOS Ventura with Intel-based MacBook Pro. I have 3 inputs in my project. One for video, one for screen audio, and another for mic audio. The other two inputs doesn't have this issue. Video input will occasionally be blocked at `isReadyForMoreMediaData` and **never return to `true`(Annoying here)** – LiYanan2004 Oct 27 '22 at 02:26

0 Answers0