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!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Background
I use AVAssetWriterInput.append to append sample buffer to the writer. Sometimes, I switch off the audio input(if user wants to temporarily disable audio input), so the append method will not be executed while the append method in video input will always be executed.
Problem
If user pause the audio and resume it later. The audio after resuming will immediately begin when user pause it (in the final video).
Example
'=' refers to CMSampleBuffer.
'|' means user paused the audio input.
Video: ---------------=================================
Audio(expected): ----=======|----------------=============
Audio(I got): ---------=======|=============----------------
I have printed the presentationTime from the audio sample buffer, it turns out it's correct.
Maybe my understanding to the AVAssetWriterInput.append is wrong?
My current solution is to always append the buffer, but when user wants to pause, I simply append an empty SampleBuffer filled with nothing.
I don't think this is the best way to deal with it.
Is there any idea to sync the buffer time with the video??
I created a function to add my course events to the calendar app using EventKit.
After learning the swift concurrency, I want to update my code to make the progress much faster, namely using the detached task or TaskGroup to add these events.
Synchronize code without detached task or task group:
func export_test() {
Task.detached {
for i in 0...15 {
print("Task \(i): Start")
let courseEvent = EKEvent(eventStore: eventStore)
courseEvent.title = "TEST"
courseEvent.location = "TEST LOC"
courseEvent.startDate = .now
courseEvent.endDate = .now.addingTimeInterval(3600)
courseEvent.calendar = eventStore.defaultCalendarForNewEvents
courseEvent.addRecurrenceRule(EKRecurrenceRule(recurrenceWith: .daily, interval: 1, end: nil))
do {
try eventStore.save(courseEvent, span: .futureEvents)
} catch { print(error.localizedDescription) }
print("Task \(i): Finished")
}
}
}
Doing the same thing using the TaskGroup :
func export_test() {
Task.detached {
await withTaskGroup(of: Void.self) { group in
for i in 0...15 {
group.addTask {
print("Task \(i): Start")
let courseEvent = EKEvent(eventStore: eventStore)
courseEvent.title = "TEST"
courseEvent.location = "TEST LOC"
courseEvent.startDate = .now
courseEvent.endDate = .now.addingTimeInterval(3600)
courseEvent.calendar = eventStore.defaultCalendarForNewEvents
courseEvent.addRecurrenceRule(EKRecurrenceRule(recurrenceWith: .daily, interval: 1, end: nil))
do {
try eventStore.save(courseEvent, span: .futureEvents)
} catch { print(error.localizedDescription) }
print("Task \(i): Finished")
}
}
}
}
}
The output of the TaskGroup version:
Task 0: Start
Task 1: Start
Task 2: Start
Task 4: Start
Task 3: Start
Task 5: Start
Task 6: Start
Task 7: Start
Task 0: Finished
Task 8: Start
Task 1: Finished
Task 9: Start
Sometimes, only a few tasks will been done, and others will not, or even never been started (I created 16 tasks but only printed 9 in this example). Sometimes, all of these events can be added.
In my point of view, I have created 16 child tasks in the TaskGroup.
Each child task will add one event to the Calendar. I think in this way, I can take the full advantage of the multi-core performance (maybe it's actually not. 🙃)
If I put the for-loop inside the group.addTask closure, it will always have the expected result, but in this way, we only have a single loop so the TaskGroup may no longer needed.
I'm really exhausted🙃🙃.
I'm trying to copying the Colorful Confetti effect in iMessage using SwiftUI Canvas and I am wondering how to apply 3D transformation on each particle.
I have tried to add a projectionTransform in order to apply a CATransform3D, but it rotates all the canvas, not a particular particle, which is not the effect I want.
Currently, I use the very basic ForEach(particles.indices, id: \.self) loop to create each particle and use .rotation3DEffect to apply that transformation, but it may result in a performance issue (so, I tried to use .drawingGroup()).
Is there any solutions to apply 3D transformation to a particular particle in a Canvas??
My code (using ForEach loop):
GeometryReader { proxy in
let size = proxy.size
TimelineView(.animation) { timeline in
let _: () = {
let now = timeline.date.timeIntervalSinceReferenceDate
model.update(at: now)
}()
ZStack {
ForEach(model.particles.indices, id: \.self) { index in
let particle = model.particles[index]
particle.shape
.fill(particle.color)
.rotation3DEffect(.degrees(particle.degrees), axis: (x: particle.x, y: particle.y, z: particle.z))
.frame(width: particle.frame.width, height: particle.frame.height)
.position(particle.frame.origin)
.tag(index)
}
}
.frame(width: size.width, height: size.height)
.drawingGroup()
}
.contentShape(Rectangle())
.gesture(
DragGesture(minimumDistance: 0)
.onEnded { _ in model.loadEffect(in: size) }
)
.task { model.loadEffect(in: size) }
}
I used a package which contains a XCFramework inside it in my widget target. It’s working fine on iOS, and macOS Widget Simulator.
But when I open widget gallery on macOS, I can’t find my widget.
I tried to run my widget directly inside /Contents/PlugIns/WidgetTestExtension.appex/Contents/MacOS/WidgetTestExtension, it prints out the error: dyld[4767]: Library not loaded: @rpath/myframework.framework/Versions/A/myframework
Description
In Live Activities, we saw many beautiful animations that powered by .numericText() like Text(time, style: .timer), or even Text with .contentTransition(.numericText()) applied.
But it seems like in normal SwiftUI View, these beautiful animations are gone. Instead, we saw a blinking result or fade-in-out result.
Is that exactly right?
ScreenShots
In Live Activity:
In normal SwiftUI View:
Error Code: error build: Command CompileSwift failed with a nonzero exit code
My Code:
.backgroundTask(.appRefresh("checkValidity")) {
// scheduleAppRefresh()
// checkRecords()
}