AVAssetWriterInputReadyForMoreMediaData总为false。
创始人
2024-11-12 20:30:21
0

问题出现的原因可能是写入速度过慢,导致下一个可用的缓冲区未能及时提供给AVAssetWriterInput。可以通过以下代码解决:

//初始化AVAssetWriterInput对象和output设置
let videoOutputSettings: Dictionary = [
    AVVideoCodecKey: AVVideoCodecType.h264,
    AVVideoWidthKey: frameSize.width,
    AVVideoHeightKey: frameSize.height
]

videoWriterInput = AVAssetWriterInput(mediaType: AVMediaType.video, outputSettings: videoOutputSettings)
let videoInputQueue = DispatchQueue(label: "video input queue")
videoWriterInput!.expectsMediaDataInRealTime = true

//将AVAssetWriterInput与AVAssetWriter绑定
let videoOutput = AVAssetWriterInputPixelBufferAdaptor(assetWriterInput: videoWriterInput!, sourcePixelBufferAttributes: nil)
videoWriter?.add(videoWriterInput!)

//在capture输出数据中调用下面的方法来写入视频数据到AVAssetWriterInput中
func writeVideo(buffer: CVPixelBuffer, time: CMTime) -> Void {
    if (videoWriterInput!.isReadyForMoreMediaData) {
        videoInputQueue.sync {
            if let adpator = videoOutput {
                adpator.append(buffer, withPresentationTime: time)
            }
        }
    }
}

在以上代码中,我们使用videoInputQueue来确保append()请求按照顺序调用,并且我们检查了AVAssetWriterInput的可用性,以确保不会在未准备好时提供更多的数据。

相关内容

热门资讯

开挂辅助安装"hhp... hhpoker软件可以玩吗开挂教程视频分享装挂详细步骤在当今的网络游戏中,hhpoker软件可以玩吗...
开挂辅助脚本"wep... wepoker轻量版辅助 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理...
开挂辅助插件"hh ... hh poker软件开挂教程视频分享装挂详细步骤在当今的网络游戏中,hh poker软件作为一种经典...
开挂辅助脚本"aap... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...
开挂辅助安装"wep... 开挂辅助安装"wepoker有透视功能吗"开挂(透视)辅助插件(有挂存在) 了解更多开挂安装加(13...
开挂辅助安装"pok... 您好:pokemmo脚本手机版这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
开挂辅助插件"wep... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...
开挂辅助神器"wpk... 【亲,wpk德州局透视 这款游戏可以开挂的,确实是有挂的,很多玩家在这款wpk德州局透视中打牌都会发...
开挂辅助神器"wep... wepoker透视app下载开挂教程视频分享装挂详细步骤在当今的网络游戏中,wepoker透视app...
开挂辅助工具"hhp... 开挂辅助工具"hhpoker有没有辅助挂"开挂(透视)辅助下载(有挂解密);无需打开直接搜索加薇13...