is Anyone experiencing freezing when attempting to get CVPixelBuffer from AVAssetReaderOutput in iOS16?

Hello. In iOS16, I faced the problem that main thread become deadlock when call copyNextSampleBuffer method in AVAssetReaderOutput in requestMediaDataWhenReady method of AVAssetWriterInput. Main thread become deadlock sometimes and main thread's call stack like below.

Thread 1 Queue : com.apple.main-thread (serial)
#0	0x00000001ebd73b48 in mach_msg2_trap ()
#1	0x00000001ebd86008 in mach_msg2_internal ()
#2	0x00000001ebd86248 in mach_msg_overwrite ()
#3	0x00000001ebd7408c in mach_msg ()
#4	0x00000001b0059564 in CA::Render::Message::send_message() ()
#5	0x00000001b0235084 in CA::Render::Encoder::send_message(unsigned int, unsigned int, unsigned int*, unsigned long) ()
#6	0x00000001b0002274 in CA::Context::commit_transaction(CA::Transaction*, double, double*) ()
#7	0x00000001b0035148 in CA::Transaction::commit() ()
#8	0x00000001b001e4c8 in CA::Transaction::flush_as_runloop_observer(bool) ()
#9	0x00000001b1004870 in _UIApplicationFlushCATransaction ()
#10	0x00000001b1151c78 in _UIUpdateSequenceRun ()
#11	0x00000001b17958f8 in schedulerStepScheduledMainSection ()
#12	0x00000001b1794ac4 in runloopSourceCallback ()
#13	0x00000001aea32394 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#14	0x00000001aea3e76c in __CFRunLoopDoSource0 ()
#15	0x00000001ae9c2650 in __CFRunLoopDoSources0 ()
#16	0x00000001ae9d7fe8 in __CFRunLoopRun ()
#17	0x00000001ae9dd314 in CFRunLoopRunSpecific ()
#18	0x00000001e851f368 in GSEventRunModal ()
#19	0x00000001b0ea23e8 in -[UIApplication _run] ()
#20	0x00000001b0ea204c in UIApplicationMain ()
#21	0x000000010506f918 in main at /Users/user/Desktop/LINE/QA/line-ios/Talk/AppDelegate.swift:72
#22	0x00000001cd8d9960 in start ()

I tried to delay some logic to call markAsFinished and finishWriting methods of AVAssetWriter but that couldn't solve this problem.

Is there anyone to experience same issue as me? If so, let me know what is workaround code if you solve this problem?

Post not yet marked as solved Up vote post of hyunjin.yoon Down vote post of hyunjin.yoon
1.6k views

Replies

Hi hyunjin,

I am seeing this too, sometimes when I try to cancel my video export the SwiftUI AsyncRenderer deadlocks in a similar way, albeit not on the main thread:

* thread #17, name = 'com.apple.SwiftUI.AsyncRenderer'
  * frame #0: 0x00000002018c6b48 libsystem_kernel.dylib`__psynch_mutexwait + 8
    frame #1: 0x0000000211d29150 libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_wait + 84
    frame #2: 0x0000000211d30310 libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_slow + 248
    frame #3: 0x00000001c638056c QuartzCore`CA::Context::commit_transaction(CA::Transaction*, double, double*) + 388
    frame #4: 0x00000001c63b55ec QuartzCore`CA::Transaction::commit() + 652
    frame #5: 0x00000001c639e8cc QuartzCore`CA::Transaction::flush_as_runloop_observer(bool) + 88
    frame #6: 0x00000001c4d55d60 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
    frame #7: 0x00000001c4cde2d0 CoreFoundation`__CFRunLoopDoObservers + 532
    frame #8: 0x00000001c4d44f30 CoreFoundation`CFRunLoopRunSpecific + 704
    frame #9: 0x00000001bf0e2334 Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
    frame #10: 0x00000001bf0e21c8 Foundation`-[NSRunLoop(NSRunLoop) run] + 64
    frame #11: 0x00000001c8709030 SwiftUI`___lldb_unnamed_symbol64823 + 800
    frame #12: 0x00000001c8707168 SwiftUI`___lldb_unnamed_symbol64774 + 88
    frame #13: 0x00000001bf0fb808 Foundation`__NSThread__start__ + 716
    frame #14: 0x0000000211d286cc libsystem_pthread.dylib`_pthread_start + 148

I have not been able to establish the cause or a workaround.

Hello,

it happens randomly to me too after I export a video composition:

* thread #7

    frame #0: 0x000000020ce9ab48 libsystem_kernel.dylib`__psynch_mutexwait + 8
    frame #1: 0x000000021d2fd150 libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_wait + 84
    frame #2: 0x000000021d304310 libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_slow + 248
  * frame #3: 0x00000001d195856c QuartzCore`CA::Context::commit_transaction(CA::Transaction*, double, double*) + 388
    frame #4: 0x00000001d198d5ec QuartzCore`CA::Transaction::commit() + 652
    frame #5: 0x00000001d19ddab4 QuartzCore`CA::Transaction::release_thread(void*) + 228
    frame #6: 0x000000021d2fcbd8 libsystem_pthread.dylib`_pthread_tsd_cleanup + 620
    frame #7: 0x000000021d2ff674 libsystem_pthread.dylib`_pthread_exit + 84
    frame #8: 0x000000021d2fc0e0 libsystem_pthread.dylib`_pthread_wqthread_exit + 76
    frame #9: 0x000000021d2fbe80 libsystem_pthread.dylib`_pthread_wqthread + 424

main thread is

 thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP

  * frame #0: 0x000000020ce99b48 libsystem_kernel.dylib`mach_msg2_trap + 8
    frame #1: 0x000000020ceac008 libsystem_kernel.dylib`mach_msg2_internal + 80
    frame #2: 0x000000020ceac248 libsystem_kernel.dylib`mach_msg_overwrite + 388
    frame #3: 0x000000020ce9a08c libsystem_kernel.dylib`mach_msg + 24
    frame #4: 0x00000001d19b1a14 QuartzCore`CA::Render::Message::send_message() + 84
    frame #5: 0x00000001d1b8e090 QuartzCore`CA::Render::Encoder::send_message(unsigned int, unsigned int, unsigned int*, unsigned long) + 940
    frame #6: 0x00000001d195a684 QuartzCore`CA::Context::commit_transaction(CA::Transaction*, double, double*) + 8860
    frame #7: 0x00000001d198d5ec QuartzCore`CA::Transaction::commit() + 652
    frame #8: 0x00000001d19768cc QuartzCore`CA::Transaction::flush_as_runloop_observer(bool) + 88
    frame #9: 0x00000001d295db44 UIKitCore`_UIApplicationFlushCATransaction + 52
    frame #10: 0x00000001d2aab740 UIKitCore`_UIUpdateSequenceRun + 84
    frame #11: 0x00000001d30f2fd0 UIKitCore`schedulerStepScheduledMainSection + 172
    frame #12: 0x00000001d30f219c UIKitCore`runloopSourceCallback + 92
    frame #13: 0x00000001d0371f54 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
    frame #14: 0x00000001d037e32c CoreFoundation`__CFRunLoopDoSource0 + 176
    frame #15: 0x00000001d0302210 CoreFoundation`__CFRunLoopDoSources0 + 244
    frame #16: 0x00000001d0317ba8 CoreFoundation`__CFRunLoopRun + 836
    frame #17: 0x00000001d031ced4 CoreFoundation`CFRunLoopRunSpecific + 612
    frame #18: 0x000000020961a368 GraphicsServices`GSEventRunModal + 164
    frame #19: 0x00000001d27fb3d0 UIKitCore`-[UIApplication _run] + 888
    frame #20: 0x00000001d27fb034 UIKitCore`UIApplicationMain + 340
    frame #21: 0x00000001d8deb308 libswiftUIKit.dylib`UIKit.UIApplicationMain(Swift.Int32, Swift.Optional<Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>>>, Swift.Optional<Swift.String>, Swift.Optional<Swift.String>) -> Swift.Int32 + 104
    frame #22: 0x00000001023da5d0 StickerTune`static UIApplicationDelegate.main() at <compiler-generated>:0
    frame #23: 0x00000001023da558 StickerTune`static AppDelegate.$main(self=StickerTune.AppDelegate) at AppDelegate.swift:13:1
    frame #24: 0x00000001023da654 StickerTune`main at <compiler-generated>:0
    frame #25: 0x00000001ee984960 dyld`start + 2528

Does anybody has a workaround for this? It's extremely frustrating as the whole UI locks up! :(

Post not yet marked as solved Up vote reply of libe Down vote reply of libe

I have the same issue

I'm seeing this as well. Cancelling a video export a couple of times freezes the app (iOS 16.1.1)

Hello

I have the same issue with AVAssetExportSession and composition animation tool. See here Will keep you updated if I find a solution. It's really annoying

I have the same issue with AVAssetExportSession and composition animation tool,is there anyone has fix it?