AVAssetWriter在附加缓冲区时由于内存问题而终止

时间:2018-07-22 12:42:02

标签: ios swift3 avassetwriter

我正在尝试将具有30帧速率的视频压缩为20帧速率,以便使用AVAssetWriter减小视频的大小。但是,在附加示例缓冲区的新副本期间,由于内存问题,我的应用被终止了。如果不更改将样本直接添加到输入中的帧速率,则可以成功进行压缩。

此编码是通过合并问题和压缩器从此处实现的: AVAssetWriter AVVideoExpectedSourceFrameRateKey (frame rate) ignored

在这里:https://pastebin.com/CQPthmjg

尝试解决问题数日,但仍然失败,我将非常感谢您的帮助。谢谢你。

videoInput.requestMediaDataWhenReady(on: videoInputQueue) {
        //request data here
        var previousTimingInfo: CMTime = kCMTimeZero
        while (videoInput.isReadyForMoreMediaData) {
            let sample = assetReaderVideoOutput.copyNextSampleBuffer()
            if (sample != nil) {

                autoreleasepool {
                    let newSample = UnsafeMutablePointer<CMSampleBuffer?>.allocate(capacity: 1) 
                    let timingInfo = UnsafeMutablePointer<CMSampleTimingInfo>.allocate(capacity: 1) 

                    CMSampleBufferGetSampleTimingInfo(sample!, 0, timingInfo)

                    timingInfo.pointee.duration = CMTimeMake(1, 20)

                    timingInfo.pointee.presentationTimeStamp = CMTimeAdd(previousTimingInfo, timingInfo.pointee.duration)
                    previousTimingInfo = timingInfo.pointee.presentationTimeStamp


                    let status: OSStatus = CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault, sample!, 1, timingInfo, newSample)
                    if status == noErr {
                        videoInput.append(newSample.pointee!)
                        print("appending sample buffer...")
                    } else {
                        print("status != noErr;\nstatus: \(status)")
                    }
                    //videoInput.append(sample!)
                }

            } else {
                videoInput.markAsFinished()
                DispatchQueue.main.async {
                    videoFinished = true
                    closeWriter()
                }
                break;
            }
        }
    }

错误发生为:

appending sample buffer...
appending sample buffer...
appending sample buffer...
appending sample buffer...
appending sample buffer...
appending sample buffer...
appending sample buffer...
appending sample buffer...
appending sample buffer...
Message from debugger: Terminated due to memory issue

0 个答案:

没有答案