Search code examples
iosswiftavfoundationavmutablecomposition

Performance issues with AVMutableComposition - scaleTimeRange


I am using scaleTimeRange:toDuration: to produce a fast-motion effect of upto 10x the original video speed.But I noticed that videos start to stutter when played through an AVPlayer at 10x.

I also noticed that on OSX's QuickTime the same composition plays smoothly.

Another question states that the reason for this is hardware limitation , but I want to know if there is a way around this , so that the fast motion effect occurs smoothly over the length of the entire video.

Video Specs

  • Format : H.264 , 1280x544
  • FPS : 25
  • Data Size : 26MB
  • Data Rate : 1.17 Mbit/s

Solution

  • I have a feeling that by playing your videos at 10x using scaleTimeRange:toDuration simply has the effect of multiplying your data rate by 10, bringing it up to 10Mbit/s, which osx machines can handle, but iOS devices cannot.

    In other words, you're creating videos that need to play back at 300 frames per second, which is pushing AVPlayer too hard.

    If I didn't know about your other question, I would have said that the solution is to export your AVComposition using AVAssetExportSession, which should result in your high FPS video being down sampled to an easier to handle 30fps, and then play that with AVPlayer.

    If AVAssetExportSession isn't working, you could try applying the speedup effect yourself, by reading the frames from the source video using AVAssetReader and writing every tenth frame to the output file using AVAssetWriter (don't forget to set the correct presentation timestamps).