5

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.

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:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVAssetWriterInput initWithMediaType:outputSettings:sourceFormatHint:] Output settings dictionary contains one or more invalid keys: ExpectedFrameRate'

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.

Eugene Alexeev
  • 1,152
  • 12
  • 32
  • I am getting same issue. Did you solve it ? – gstream Nov 12 '18 at 15:53
  • Hello @gstream79! If I'm not wrong, key `AVVideoExpectedSourceFrameRateKey ` should be put into `AVVideoCompressionPropertiesKey` or something like that. But I don't know for sure because I didn't use this property eventually. – Eugene Alexeev Nov 12 '18 at 18:35
  • Thanks for your answer @Eugene Alexeev, I've tried to use AVVideoExpectedSourceFrameRateKey but no luck with it. – gstream Nov 12 '18 at 21:42
  • How did you solve this problem? You had to give up? or did use another way to set fps ? – gstream Nov 13 '18 at 16:10

1 Answers1

0

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]                                         
        ]

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 (frame rate) ignored