I have two solutions to this problem:
SOLUTION A
- Convert the asset to an
AVMutableComposition
. - For every second keep only one frame , by removing
timing
for all the other frames usingremoveTimeRange(...)
method.
SOLUTION B
- Use the
AVAssetReader
to extract all individual frames as an array ofCMSampleBuffer
- Write
[CMSampleBuffer]
back into a movie skipping every 20 frames or so as per requirement. - Convert the obtained video file to an
AVMutableComposition
and usescaleTimeRange(..)
to reduce overalltimeRange
of video for timelapse effect.
PROBLEMS
- The first solution is not suitable for full HD videos , the video freezes in multiple place and the seekbar shows inaccurate timing .
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.
- The second solution is incredibly slow. For a 10 minute HD video the memory would run upto infinity since all execution is done in memory.
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!