ios - __copy_helper_block_ 在 AVFoundation 中崩溃

标签 ios swift avfoundation gpuimage

我的视频处理应用程序发生奇怪的崩溃。它使用 AVFoundation 处理视频和音频,使用 GPUImage 进行过滤。我自己从未遇到过这个问题,但在将其发布到 App Store 后,它经常出现在 Crashlytics 中。这是崩溃的日志:

Thread : Crashed: AVPlayerItemOutput queue
0  libobjc.A.dylib                0x00000001986f80b4 objc_retain + 20
1  libsystem_blocks.dylib         0x0000000198d79bf8 _Block_object_assign + 320
2  AVFoundation                   0x0000000186895a34 __copy_helper_block_171 + 36
3  libsystem_blocks.dylib         0x0000000198d79738 _Block_copy_internal + 384
4  libdispatch.dylib              0x0000000198d252fc _dispatch_Block_copy + 36
5  libdispatch.dylib              0x0000000198d2685c dispatch_async + 68
6  AVFoundation                   0x00000001868959ac -[AVPlayerItemVideoOutput _dispatchOutputSequenceWasFlushed] + 112
7  libdispatch.dylib              0x0000000198d2536c _dispatch_client_callout + 16
8  libdispatch.dylib              0x0000000198d2e6e8 _dispatch_barrier_sync_f_invoke + 76
9  AVFoundation                   0x00000001868940a8 AVPlayerItemVideoOutput_figVCSequentialAvailable + 196
10 MediaToolbox                   0x000000018a3c16f8 FigVisualContextImageAvailableSequential + 108
11 MediaToolbox                   0x000000018a348ce8 itemremote_postNotificationWithPayload + 3996
12 MediaToolbox                   0x000000018a342d60 FigPlayerRemoteCallbacksServer_SendNotifyPing + 924
13 MediaToolbox                   0x000000018a342998 _XSendNotifyPing + 60
14 MediaToolbox                   0x000000018a33f0d4 figmoviecallbacks_server + 112
15 MediaToolbox                   0x000000018a33f018 fpr_ClientPortCallBack + 208
16 CoreFoundation                 0x0000000187f44ce0 __CFMachPortPerform + 180
17 CoreFoundation                 0x0000000187f598fc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
18 CoreFoundation                 0x0000000187f5985c __CFRunLoopDoSource1 + 436
19 CoreFoundation                 0x0000000187f577dc __CFRunLoopRun + 1640
20 CoreFoundation                 0x0000000187e851f4 CFRunLoopRunSpecific + 396
21 GraphicsServices               0x00000001910135a4 GSEventRunModal + 168
22 UIKit                          0x000000018c7b6784 UIApplicationMain + 1488
23 MerryVideoEditor               0x000000010024b804 main (main.m:16)
24 libdyld.dylib                  0x0000000198d4ea08 start + 4

这就是我将 AVFoundation 连接到 GPUImage 的方式:

class ProjectEditorViewController: UIViewController {
   private var videoPlayerView = VideoPlayerView()
   private var movieFile: GPUImageMovie!   
   private var currentComposition: AVComposition!
   //...and other properties
}

// MARK: - Filtering & Playback
extension ProjectEditorViewController{
   func updatePlayer() {

      currentFilter.removeAllTargets()
      movieFile?.removeAllTargets()
      movieFile?.endProcessing()

      let time = self.videoPlayerView.player?.currentItem.currentTime() ?? kCMTimeZero

      let (composition, audioMix) = compositionBuilder.buildCompositionFromTimeLine(timeLine)
      videoPlayerView.setAsset(composition)
      videoPlayerView.playerItem.audioMix = audioMix

      movieFile = GPUImageMovie(playerItem: videoPlayerView.player.currentItem)
      currentFilter.applyFromOutput(movieFile, toInput: gpuPlayerView)
      movieFile.startProcessing()

      addSyncLayerIfNeededForComposition(composition)

      videoPlayerView.player.seekToTime(time, toleranceBefore: kPlayerToleranceSeekTime, toleranceAfter: kPlayerToleranceSeekTime)
      currentComposition = composition

   }

   func updatePlayerFilter(){          
      if movieFile != nil{
         movieFile.removeAllTargets()
         currentFilter.applyFromOutput(movieFile, toInput: gpuPlayerView)
         if(!videoPlayerView.isPlaying) { movieFile.startProcessing() }
         addSyncLayerIfNeededForComposition(currentComposition)
      }else{
         updatePlayer()
      }
   }       
}

知道我的代码有什么问题吗?非常感谢任何问题、评论、提示和答案。

最佳答案

这是 GPUImageMovie 中的一个问题 - 当实例将自身添加为 AVPlayerItemVideoOutput 委托(delegate)时: [playerItemOutput setDelegate:self queue:videoProcessingQueue],当 GPUImageMovie 实例解除分配时,playerItemOutput 不会释放其委托(delegate)。稍后,这会导致从已释放的对象 (outputSequenceWasFlushed:) 调用方法,然后发生崩溃。这是在 NSZombie 检测器的帮助下发现的,我通过在 GPUImageMovie dealloc 方法中添加它来修复它:[playerItemOutput setDelegate:nil queue:nil];

祝你好运,尼基塔 ;)

关于ios - __copy_helper_block_ 在 AVFoundation 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29103254/

相关文章:

ios - 从 Appstore 下载但在本地加载时不会崩溃的应用程序内购买应用程序崩溃

ios - 将嵌套类写入 plist

c++ - 将 std::u16string 转换为 NSString

ios - 在 iOS 上缩小图像尺寸最节省内存的方法是什么?

swift - 是否有与 GCC `__attribute__((constructor))` 等效的 Swift?

ios - 使用 AVAssetWriter 而不是 AVAssetExportSession 导出 AVMutableVideoComposition

ios - AVPlayer 在播放 HLS/AES 加密视频之前发出无关的 http 请求

iPhone - 使用 AVAssetWriterInputPixelBufferAdaptor 录制视频时从麦克风捕获音频

ios - 如何在 iOS 中录制音频乐器?

ios - 对标准附件 View 的约束