Post

Replies

Boosts

Views

Activity

AVVideoCompositionCoreAnimationTool and AVAssetExportSession freezes the app randomly
Hi there, So I've been banging my head for the last week, because we have an issue in our app where it's freezing on export while the composition has a AVVideoCompositionCoreAnimationTool as animationTool Before extracting the code to an app I can share, or submit a TSIs, I was wondering if this rings a bell to someone. Basically, we're not doing something too crazy We create an AVAssetExportSession from a composition, some audio and some layers to animate.     func makeExportable(configuration: ExportConfiguration) throws -> AVAssetExportSession {         if let animationLayer {             let rect = CGRect(origin: .zero, size: configuration.videoSize)             let videoAnimationLayer = CALayer()             videoAnimationLayer.frame = rect             let videoLayer = CALayer()             videoLayer.frame = rect             videoAnimationLayer.addSublayer(videoLayer)             videoAnimationLayer.addSublayer(animationLayer)             videoAnimationLayer.isGeometryFlipped = true             let animationTool = AVVideoCompositionCoreAnimationTool(postProcessingAsVideoLayer: videoLayer,                                                                     in: videoAnimationLayer)             avVideoComposition.animationTool = animationTool         }         guard             let session = AVAssetExportSession(asset: avComposition,                                                presetName: configuration.avAssetExportPresetName) else {             throw CompositionError.invalidExportSession         }         session.audioMix = audioMix         session.videoComposition = avVideoComposition         return session)     } Then we run await session.export() If we do that multiple times in a row (there are no specific triggers, I can have a 3s video with 40 CALayers or a 30s with 1500 layers, it could happen on the first export or the 20th, ...), then at some point, the app will just have a severe hang with the following stack trace (if I pause the debug session). If ever, I remove the avVideoComposition.animationTool = animationTool line from the export session creation, then the app does not hang... Also, I encounter the issue with the fact that it's crashing on a sim but running fine on a device. Some api_misuse crash (see [here)]. Could this be related, idk...(https://developer.apple.com/forums/thread/133681) Anyway... Completely stuck here, and surprised that such a thing would have an issue on AVFoundation. We're probably not the onliest using CoreAnimation on a video export... Thanks! Marian
4
4
1.3k
Mar ’23