gpt4 book ai didi

ios - AVAssetWriter 写入黑屏视频

转载 作者:行者123 更新时间:2023-11-30 13:58:59 25 4
gpt4 key购买 nike

我使用以下代码附加PixelBuffer,但输出视频是黑屏(CIImage 是正常的)。我认为问题出现在 newPixelBuffer 中。

func recordRealTimeFilterVideoPerFrame(sampleBuffer: CMSampleBuffer, outputImage: CIImage) {

let formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer)
currentSampleTime = CMSampleBufferGetOutputPresentationTimeStamp(sampleBuffer)
currentDimensions = CMVideoFormatDescriptionGetDimensions(formatDescription!)

guard assetWriter?.status == .Writing else { return }
guard (isRecording && assetWriterPixelBufferInput?.assetWriterInput.readyForMoreMediaData != nil) else { return }
guard let bufferPool = assetWriterPixelBufferInput?.pixelBufferPool else { print("bufferPool is nil"); return }

var newPixelBuffer = UnsafeMutablePointer<CVPixelBuffer?>.alloc(1)
CVPixelBufferPoolCreatePixelBuffer(nil, bufferPool, newPixelBuffer)

filterPreviewView?.ciContext.render(outputImage,
toCVPixelBuffer: newPixelBuffer.memory!,
bounds: outputImage.extent,
colorSpace: nil)

let success = assetWriterPixelBufferInput?.appendPixelBuffer(newPixelBuffer.memory!, withPresentationTime: currentSampleTime!)

if success == false {
print("pixel append false")
}

newPixelBuffer.destroy()
newPixelBuffer.dealloc(1)
newPixelBuffer = nil
}

最佳答案

您的 currentSampleTime 是否从零开始?

如果不是,您应该减去第一个值

 currentSampleTime  = CMSampleBufferGetOutputPresentationTimeStamp(sampleBuffer)

来自 currentSampleTime 的所有后续值。

关于ios - AVAssetWriter 写入黑屏视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33212222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com