diff --git a/Sources/RTMP/RTMPMuxer.swift b/Sources/RTMP/RTMPMuxer.swift index 77c266e48..97611c8f0 100644 --- a/Sources/RTMP/RTMPMuxer.swift +++ b/Sources/RTMP/RTMPMuxer.swift @@ -61,9 +61,6 @@ extension RTMPMuxer: VideoEncoderDelegate { } func sampleOutput(video sampleBuffer: CMSampleBuffer) { - guard let data: Data = sampleBuffer.dataBuffer?.data else { - return - } let keyframe: Bool = !sampleBuffer.dependsOnOthers var compositionTime: Int32 = 0 let presentationTimeStamp: CMTime = sampleBuffer.presentationTimeStamp @@ -73,6 +70,9 @@ extension RTMPMuxer: VideoEncoderDelegate { } else { compositionTime = Int32((decodeTimeStamp.seconds - decodeTimeStamp.seconds) * 1000) } + guard let data: Data = sampleBuffer.dataBuffer?.data, 0 <= delta else { + return + } let delta: Double = (videoTimestamp == kCMTimeZero ? 0 : decodeTimeStamp.seconds - videoTimestamp.seconds) * 1000 var buffer: Data = Data([((keyframe ? FLVFrameType.key.rawValue : FLVFrameType.inter.rawValue) << 4) | FLVVideoCodec.avc.rawValue, FLVAVCPacketType.nal.rawValue]) buffer.append(contentsOf: compositionTime.bigEndian.data[1..<4])