0

I have an AVMutableComposition made from a Slo-Mo video. In AVPlayer it plays in the right speed, because I have requested it from Photos using PHVideoRequestOptions.Original which doesn't include the Slo-Mo part for the video. However, exporting the mutable composition will export it with full FPS, which causes the Slo-Mo to come back if the FPS is too high.

How can I export video with frame rate of 30? Is there a specific file type that doesn't include slow motion or some other way to do this?

Two (bad) solutions I've found:

  1. Setting AVAssetExportSession to AVAssetExportPresetMediumQualityor less will cause the frame rate to drop but quality will also be worse. Not good.
  2. Setting AVAssetExportSession.videoComposition to a video composition with frameDuration that is CMTimeMake(1, 30) but it takes really long to export the video with that, which is not good either. I don't know what causes it to take so long.
Aleksi Sjöberg
  • 1,454
  • 1
  • 12
  • 34

1 Answers1

3

According to Apple DTS, currently the best solution is the one I mentioned as number 2. Here it's in more detail:

        let videoComposition = AVMutableVideoComposition(propertiesOfAsset: mutableComposition)
        videoComposition.frameDuration = CMTimeMake(1, 30) // Changes FPS to 30

        let exportSession = AVAssetExportSession(asset: mutableComposition, presetName: AVAssetExportPresetHighestQuality)

        exportSession?.videoComposition = videoComposition

        exportSession?.outputURL = temporaryURL
        exportSession?.outputFileType = AVFileTypeMPEG4                     

        exportSession?.exportAsynchronouslyWithCompletionHandler({
            // Handling the export
        })

Exporting with video composition seems to take much more time than it does without it, but I've filed an enchantment request about improving this situation as suggested by Apple DTS.

Aleksi Sjöberg
  • 1,454
  • 1
  • 12
  • 34
  • 1
    This worked for me. There is only a small error in the code: `videoComposition = CMTimeMake(1, 30) // Changes FPS to 30` should be `videoComposition.frameDuration = CMTimeMake(1, 30)` – Ruud Visser Jun 02 '16 at 22:10
  • @RuudVisser thanks for pointing it out! Maybe saves someone from frustration. :) – Aleksi Sjöberg Jun 02 '16 at 22:31