gpt4 book ai didi

swift - 是否可以通过在 iOS 中使用具有质量设置的 jpeg 编码器来记录并保存到文件?

转载 作者:可可西里 更新时间:2023-11-01 01:00:45 24 4
gpt4 key购买 nike

Apple 基本上提供了 2 种编码器,h264 或 avc1 和 jpeg。

let settings:[String:AnyObject] = [
AVVideoCodecKey: AVVideoCodecJPEG,
AVVideoWidthKey: 720,
AVVideoHeightKey: 1280,
AVVideoQualityKey: 0.5
]
//Line below is where the compilation error happened
VideoInput = AVAssetWriterInput(mediaType: AVMediaTypeVideo, outputSettings: settings)
VideoInput.expectsMediaDataInRealTime = true
assetWriter.addInput(VideoInput)

现在,如果我从字典中删除 AVVideoQualityKey:0.5,它会完美运行。用 key ?否。编译错误,错误消息如下。

Output settings dictionary contains one or more invalid keys: Quality'

当我的字典中没有 AVVideoQualityKey 时,最终的电影文件是用 mjpeg 编码器编码的。它太大了,这就是为什么我需要将 jpeg 质量 key 设置为 0.5。

我想到了另一种方法来处理 samplebuffer,将它们转换为 cvpixelbuffer 并自己编码,然后将它们转换回来并用 assetwriter 写入。但它似乎不太有效,因为我确定我是否可以使用 AVVideoQualityKey,编码是硬件加速的。

最佳答案

我遇到了同样的问题。但我找到了答案。试试这个:

let videoSettings: [String: AnyObject] = [
AVVideoCodecKey: AVVideoCodecJPEG,
AVVideoWidthKey: 720,
AVVideoHeightKey: 1280,
AVVideoCompressionPropertiesKey: [AVVideoQualityKey: 0.5]
]

这对我有用。

关于swift - 是否可以通过在 iOS 中使用具有质量设置的 jpeg 编码器来记录并保存到文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34716558/

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