5

我正在使用AVSampleBufferDisplayLayer解码和显示从服务器流式传输的 H.264 视频。当我的应用程序进入后台然后返回前台时,解码过程被搞砸了并且AVSampleBufferDisplayLayer失败了。我看到的错误是:

H.264 decoding layer has failed: Error Domain=AVFoundationErrorDomain
  Code=-11847 "Operation Interrupted" UserInfo=0x17426c500
  {NSUnderlyingError=0x17805fe90 "The operation couldn’t be completed.
    (OSStatus error -12084.)",
   NSLocalizedRecoverySuggestion=Stop other operations and try again.,
   NSLocalizedDescription=Operation Interrupted}

有没有其他人遇到过这样的问题AVSampleBufferDisplayLayer?这是什么意思?

当我收到错误时,我尝试销毁AVSampleBufferDisplayLayer并创建一个新的,但随后我开始从 H.264 解码器收到其他错误:

Error Domain=AVFoundationErrorDomain Code=-11821 "Cannot Decode"
UserInfo=0x1740e9700 {AVErrorMediaSubTypeKey=(1635148593),
  NSLocalizedFailureReason=The media data could not be decoded. It may be damaged.,
  NSUnderlyingError=0x174247680 "The operation couldn’t be completed. (OSStatus error -12909.)",
  AVErrorMediaTypeKey=vide,
  AVErrorPresentationTimeStampKey=CMTime: {7/30 = 0.233},
  NSLocalizedDescription=Cannot Decode}

在失败之前我没有收到任何这些错误AVSampleBufferDisplayLayer

4

3 回答 3

0

重建一个新的 AVSampleBufferDisplayLayer 后,您应该将它与最后一个最近的 IDR 帧排入队列,除了当前帧是 IDR,这意味着,您应该在解码时将 nalus 保存在一个 GOP 中,并在下一个 IDR 到来时将其删除。

于 2016-07-07T08:56:19.373 回答
0

我遇到了同样的问题,并且能够使用以下代码解决。我需要使用 pubDidBecomeActive 事件而不是 willEnterForeground 事件来处理 Siri 也被激活的情况。

class RoomState: NSObject, ObservableObject  {
    private var subs = [AnyCancellable]()
    @Published var displayLayer = AVSampleBufferDisplayLayer()

    override init() {
        super.init()
        let pubDidBecomeActive = NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)
        subs.append(pubDidBecomeActive.sink { [weak self] _ in
            self?.displayLayer = AVSampleBufferDisplayLayer()
        })
    }
}

于 2021-07-06T22:42:01.010 回答
0

我解决了

// create renderer
let renderingLayer = AVSampleBufferDisplayLayer()

// when enqueue data
if renderingLayer.status == .failed {
    // this way
    renderingLayer.flushAndRemoveImage()
}
于 2021-04-30T09:15:35.363 回答