Skip to content

Commit

Permalink
Use CMClock.hostTimeClock in blogpost
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlokhorst committed Jan 27, 2024
1 parent 79d5acf commit 81fe134
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Content/blog/2023-01-31-recording-screencapturekit.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Prepare the AVAssetWriter by calling startWriting, then start a session:

```swift
assetWriter.startWriting()
let now = CMTime(seconds: ProcessInfo.processInfo.systemUptime, preferredTimescale: 100)
let now = CMClock.hostTimeClock.time
assetWriter.startSession(atSourceTime: now)
```

Expand All @@ -63,7 +63,7 @@ func stream(_ stream: SCStream, didOutputSampleBuffer sampleBuffer: CMSampleBuff
To stop the recording, end the session on the AVAssetWriter and finish writing:

```swift
let now = CMTime(seconds: ProcessInfo.processInfo.systemUptime, preferredTimescale: 100)
let now = CMClock.hostTimeClock.time
assetWriter.endSession(atSourceTime: now)
videoInput.markAsFinished()
await assetWriter.finishWriting()
Expand Down Expand Up @@ -181,7 +181,7 @@ With one final edge case; If we make a 10 second recording of a screen where not
// In case no changes happend on screen, and the last frame is from long ago
// This ensures the recording is of the expected length
if let originalBuffer = lastSampleBuffer {
let now = CMTime(seconds: ProcessInfo.processInfo.systemUptime, preferredTimescale: 100)
let now = CMClock.hostTimeClock.time
let additionalTime = now - streamOutput.firstSampleTime
let timing = CMSampleTimingInfo(duration: originalBuffer.duration, presentationTimeStamp: additionalTime, decodeTimeStamp: originalBuffer.decodeTimeStamp)
let additionalSampleBuffer = try CMSampleBuffer(copying: originalBuffer, withNewTiming: [timing])
Expand Down

0 comments on commit 81fe134

Please sign in to comment.