user7404038
user7404038

Reputation:

Create a timelapse from a normal video in iOS

I have two solutions to this problem:

SOLUTION A

  1. Convert the asset to an AVMutableComposition.
  2. For every second keep only one frame , by removing timing for all the other frames using removeTimeRange(...) method.

SOLUTION B

  1. Use the AVAssetReader to extract all individual frames as an array of CMSampleBuffer
  2. Write [CMSampleBuffer] back into a movie skipping every 20 frames or so as per requirement.
  3. Convert the obtained video file to an AVMutableComposition and use scaleTimeRange(..) to reduce overall timeRange of video for timelapse effect.

PROBLEMS

e.g. A 12 second timelapse might only be shown to have a duration of 5 seconds, so it keeps playing even when the seek has finished.

I mean the timing of the video gets all messed up for some reason.


I am searching for a technique that can produce a timelapse for a video right away , without waiting time .Solution A kind of does that , but is unsuitable because of timing problems and stuttering.

Any suggestion would be great. Thanks!

Upvotes: 1

Views: 1437

Answers (1)

Mick
Mick

Reputation: 25491

You might want to experiment with the inbuilt thumbnail generation functions to see if they are fast/effecient enough for your needs.

They have the benefit of being optimised to generate images efficiently from a video stream.

Simply displaying a 'slide show' like view of the thumbnails one after another may give you the effect you are looking for.

There is iinfomrtaion on the key class, AVAssetImageGenerator, here including how to use it to generate multiple images:

Upvotes: 0

Related Questions