如何将期望的帧速率设置为AVAssetWriterInput [英] How to set expected framerate to AVAssetWriterInput
问题描述
我有一个应用程序,可以用不同的方式对视频进行编码并将其保存到照片库-它可以剪切特定的时间范围,添加图片,文本等.一切正常,直到我尝试对120 fps以上的视频进行编码.问题在于视频似乎动作缓慢,我根本不追求这个目标.
I have an app which encodes videos in different ways and saves it to Photos library - it can cut specific time range, add pictures, text, etc. Everything is working perfectly till I try to encode video 120+ fps. The problem is that video appears to be slow-motioned and I don't pursue that goal at all.
在这里关于 AVAssetWritterInput
的属性(称为 AVVideoExpectedSourceFrameRateKey
),但问题是当我尝试将此参数应用于我的 AVAssetWritterInput
时,我出现此错误:
Here I found out about property for AVAssetWritterInput
which is called AVVideoExpectedSourceFrameRateKey
, but the problem is that when I try to apply this parameter to my AVAssetWritterInput
, I'm getting this error:
***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'***-[AVAssetWriterInput initWithMediaType:outputSettings:sourceFormatHint:]输出设置字典包含一个或多个无效键:ExpectedFrameRate'
这是我的 AVAssetWriterInput
初始化,一点都不花哨:
Here's my AVAssetWriterInput
initialization, nothing fancy at all:
let input = AVAssetWriterInput(mediaType: AVMediaTypeVideo, outputSettings: [AVVideoCodecKey: AVVideoCodecJPEG,
AVVideoHeightKey: correctedContentSize.height,
AVVideoWidthKey: correctedContentSize.width,
AVVideoExpectedSourceFrameRateKey: 60])
任何帮助将不胜感激.谢谢.
Any help would be appreciated. Thanks.
推荐答案
问题出在您将关键字放在字典"中以将设置加载到outputSettings中的方式.实际上,键"AVVideoExpectedSourceFrameRateKey"应该放在嵌套的Dictionary中,并且键是"AVVideoCompressionPropertiesKey".因此,您可以使用类似于Dictionary的Dictionary作为outputSettings.它应该看起来像这样:
The problem comes from the way you're placing the key inside of your Dictionary to load the settings into the outputSettings. The key 'AVVideoExpectedSourceFrameRateKey' is actually supposed to go inside a nested Dictionary, and the key for it is 'AVVideoCompressionPropertiesKey'. So you have a Dictionary of Dictionaries of sorts as the outputSettings instead. It should look something like this:
let outputSettings:[String: Any] = [
AVVideoCodecKey: AVVideoCodecJPEG,
AVVideoHeightKey: correctedContentSize.height,
AVVideoWidthKey: correctedContentSize.width
AVVideoCompressionPropertiesKey:
[AVVideoExpectedSourceFrameRateKey: 60]
]
如果您想在回放视频时使用它来调整Feed,可以在此处找到有关此过程的更多信息:
More info on this process can be found here if you'd like to use this to adjust the feed when playing this video back:
AVAssetWriter AVVideoExpectedSourceFrameRateKey(帧速率)已忽略
这篇关于如何将期望的帧速率设置为AVAssetWriterInput的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!