AVMutableVideoComposition - CoreAnimation:警告,删除了未提交 CATransaction 的线程

Posted

技术标签:

【中文标题】AVMutableVideoComposition - CoreAnimation:警告,删除了未提交 CATransaction 的线程【英文标题】:AVMutableVideoComposition - CoreAnimation: warning, deleted thread with uncommitted CATransaction 【发布时间】:2013-10-28 15:58:37 【问题描述】:

我正在使用 AVMutableComposition 处理一些基本的视频合成 - 目前是一个带有文本层 (CATextLayer) 的视频层 (AVMutableVideoComposition)。

看起来一切正常,但是当我让它通过“AVMutableComposition exportAsynchronouslyWithCompletionHandler”导出时,它会关闭并完成但返回此错误:

CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
0   QuartzCore                          0x00007fff8a106959 _ZN2CA11Transaction4pushEv + 219
1   QuartzCore                          0x00007fff8a106531 _ZN2CA11Transaction15ensure_implicitEv + 273
2   QuartzCore                          0x00007fff8a10d66f _ZN2CA5Layer13thread_flags_EPNS_11TransactionE + 37
3   QuartzCore                          0x00007fff8a10d5a7 _ZN2CA5Layer4markEPNS_11TransactionEjj + 79
4   QuartzCore                          0x00007fff8a112cac _ZN2CA5Layer27contents_visibility_changedEPNS_11TransactionEb + 216
5   QuartzCore                          0x00007fff8a112b65 _ZN2CA5Layer12mark_visibleEPNS_11TransactionEb + 261
6   QuartzCore                          0x00007fff8a112b26 _ZN2CA5Layer12mark_visibleEPNS_11TransactionEb + 198
7   QuartzCore                          0x00007fff8a112b26 _ZN2CA5Layer12mark_visibleEPNS_11TransactionEb + 198
8   QuartzCore                          0x00007fff8a1128d1 _ZN2CA5Layer11set_visibleEj + 335
9   QuartzCore                          0x00007fff8a1126b9 _ZN2CA7Context9set_layerEPKv + 75
10  MediaToolbox                        0x00007fff857f155b FigCoreAnimationRendererInvalidate + 108
11  CoreFoundation                      0x00007fff8ec763df CFRelease + 511
12  MediaToolbox                        0x00007fff857d3a6b FigVideoCompositionProcessorInvalidate + 675
13  MediaToolbox                        0x00007fff85791341 FigAssetWriterCreateWithURL + 18573
14  MediaToolbox                        0x00007fff85791f7b FigAssetWriterCreateWithURL + 21703
15  CoreMediaAuthoringCrunchers         0x00000001046e2b99 AssetAudiosourcer_CreateInstance + 3865

如果我注释掉以下行,我发现这会消失 - 但是 CATextLayer 没有呈现:

videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];

有什么想法吗?

亚当

【问题讨论】:

【参考方案1】:

您必须确保在主线程上进行任何 UI 绘制。您注释掉的行可能在内部进行了一些绘图,因此您要确保此代码在主线程上执行。执行此操作的几种方法是使用函数dispatch_async() 或方法performSelectorOnMainThread:withObject:waitUntilDone:performSelectorOnMainThread:withObject:waitUntilDone:modes:

- (void) someMethod

    // You may need to load a container object to pass as myCustomData whose
    // contents you then access in myCustomDrawing: if the data isn't accessible
    // as instance data.

    [...]

    // Perform all drawing/UI updates on the main thread.
    [self performSelectorOnMainThread:@selector(myCustomDrawing:)
                           withObject:myCustomData
                        waitUntilDone:YES];

    [...]


- (void) myCustomDrawing:(id)myCustomData

    // Perform any drawing/UI updates here.
    videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer
                                                                                                                                  inLayer:parentLayer];

有关dispatch_async()performSelectorOnMainThread:withObjects:waitUntilDone: 之间区别的相关帖子,请参阅Whats the difference between performSelectorOnMainThread and dispatch_async on main queue?

【讨论】:

Dalmazio 非常感谢您的回信。我最终得出了这个结论,并将所有的 GUI 更新都放在了 maid 线程上。尽管如此,还是感谢您的回复!

以上是关于AVMutableVideoComposition - CoreAnimation:警告,删除了未提交 CATransaction 的线程的主要内容,如果未能解决你的问题,请参考以下文章

在播放期间更改 AVPlayerItem 的 videoComposition 属性 (AVMutableVideoComposition)

AVMutableVideoComposition - CoreAnimation:警告,删除了未提交 CATransaction 的线程

在 AVMutableVideoComposition 中创建一个按时间间隔更改的 CATextlayer

AVVideoCompositionCoreAnimationTool 和 CALayer 在纵向模式下?

如何使用 AVFoundation 编辑和播放 HDR 视频。