Created
September 23, 2024 20:24
-
-
Save leonid-shevtsov/d4927f265b190dfa061158278129cff8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let writerReadySemaphore = DispatchSemaphore(value: 0) | |
let frameWrittenSemaphore = DispatchSemaphore(value: 0) | |
let isFinished = Atomic<Bool>(false) | |
let queue = DispatchQueue(label: "gif_convertor") | |
videoWriterInput.requestMediaDataWhenReady(on: queue) { | |
while !isFinished.load(ordering: .sequentiallyConsistent), | |
videoWriterInput.isReadyForMoreMediaData | |
{ | |
writerReadySemaphore.signal() | |
frameWrittenSemaphore.wait() | |
} | |
} | |
// ... | |
while index < gif.frameCount { | |
writerReadySemaphore.wait() | |
// ...write next frame | |
index+=1 | |
if index == gif.frameCount { | |
isFinished.store(true, ordering: .sequentiallyConsistent) | |
} | |
frameWrittenSemaphore.signal() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment