【问题标题】:How to set expected framerate to AVAssetWriterInput如何将预期帧速率设置为 AVAssetWriterInput
【发布时间】:2018-09-01 07:49:06
【问题描述】:

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

Here 我发现AVAssetWritterInput 的属性称为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 初始化,没什么花哨的:

let input = AVAssetWriterInput(mediaType: AVMediaTypeVideo, outputSettings: [AVVideoCodecKey: AVVideoCodecJPEG,
                                                                                         AVVideoHeightKey: correctedContentSize.height,
                                                                                         AVVideoWidthKey: correctedContentSize.width,
                                                                                         AVVideoExpectedSourceFrameRateKey: 60])

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

【问题讨论】:

  • 我遇到了同样的问题。你解决了吗?
  • 你好@gstream79!如果我没记错的话,应该将密钥AVVideoExpectedSourceFrameRateKey 放入AVVideoCompressionPropertiesKey 或类似的东西中。但我不确定,因为我最终没有使用这个属性。
  • 感谢您的回答@Eugene Alexeev,我尝试使用 AVVideoExpectedSourceFrameRateKey 但没有运气。
  • 你是怎么解决这个问题的?你不得不放弃?还是使用其他方式设置 fps ?

标签: ios video frame-rate avassetwriter avassetwriterinput


【解决方案1】:

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

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

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

AVAssetWriter AVVideoExpectedSourceFrameRateKey (frame rate) ignored

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-09
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    相关资源
    最近更新 更多