如何将预期帧速率设置为AVAssetWriterInput

时间:2018-03-22 18:31:26

标签: ios video frame-rate avassetwriter avassetwriterinput

我有一个应用程序,以不同的方式对视频进行编码并将其保存到照片库 - 它可以缩短特定的时间范围,添加图片,文本等。一切都很完美,直到我尝试编码视频120+ fps。问题是视频似乎是慢动作的,我根本不追求这个目标。

Here我发现了名为AVAssetWritterInput的{​​{1}}的属性,但问题是当我尝试将此参数应用于AVVideoExpectedSourceFrameRateKey时,我'得到这个错误:

AVAssetWritterInput

这是我的*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVAssetWriterInput initWithMediaType:outputSettings:sourceFormatHint:] Output settings dictionary contains one or more invalid keys: ExpectedFrameRate'初始化,完全没有任何想象力:

AVAssetWriterInput

任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:0)

问题来自于您将密钥放入字典以将设置加载到 outputSettings 中的方式。键 'AVVideoExpectedSourceFrameRateKey' 实际上应该放在嵌套字典中,它的键是 'AVVideoCompressionPropertiesKey'。所以你有一个字典作为输出设置。它应该看起来像这样:

let outputSettings:[String: Any] = [
            AVVideoCodecKey: AVVideoCodecJPEG,
            AVVideoHeightKey: correctedContentSize.height,
            AVVideoWidthKey: correctedContentSize.width
            AVVideoCompressionPropertiesKey: 
               [AVVideoExpectedSourceFrameRateKey: 60]                                         
        ]

如果您想在播放此视频时使用它来调整提要,可以在此处找到有关此过程的更多信息:

AVAssetWriter AVVideoExpectedSourceFrameRateKey (frame rate) ignored