我有一个应用程序,它以不同的方式编码视频,并将其保存到图片库-它可以削减特定的时间范围,添加图片,文字等一切都是完美的,直到我尝试编码视频120+帧。问题是视频看起来动作很慢,而我根本就不追求这个目标。
Here我发现了名为AVVideoExpectedSourceFrameRateKey的AVAssetWritterInput的属性,但问题是,当我尝试将此参数应用于我的AVAssetWritterInput时,我收到以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVAssetWriterInput initWithMediaType:outputSettings:sourceFormatHint:] Output settings dictionary contains one or more invalid keys: ExpectedFrameRate'
这是我的AVAssetWriterInput初始化,一点也不花哨:
let input = AVAssetWriterInput(mediaType: AVMediaTypeVideo, outputSettings: [AVVideoCodecKey: AVVideoCodecJPEG,
AVVideoHeightKey: correctedContentSize.height,
AVVideoWidthKey: correctedContentSize.width,
AVVideoExpectedSourceFrameRateKey: 60])任何帮助都将不胜感激。谢谢。
发布于 2021-03-08 01:43:32
问题来自于您将键放在字典中以将设置加载到outputSettings中的方式。关键字'AVVideoExpectedSourceFrameRateKey‘实际上应该放在一个嵌套的字典中,它的关键字是'AVVideoCompressionPropertiesKey’。因此,您有一本字典作为outputSettings。它应该看起来像这样:
let outputSettings:[String: Any] = [
AVVideoCodecKey: AVVideoCodecJPEG,
AVVideoHeightKey: correctedContentSize.height,
AVVideoWidthKey: correctedContentSize.width
AVVideoCompressionPropertiesKey:
[AVVideoExpectedSourceFrameRateKey: 60]
]如果您想在回放此视频时使用此功能调整提要,请在此处找到有关此过程的更多信息:
AVAssetWriter AVVideoExpectedSourceFrameRateKey (frame rate) ignored
https://stackoverflow.com/questions/49436027
复制相似问题