1

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

  • 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!

Community
  • 1
  • 1
  • Use solution B, except modify the timestamps as you go with `CMSampleBufferCreateCopyWithNewTiming()`. Then there is no need for your step 3. – Rhythmic Fistman May 12 '17 at 23:25
  • The fact that `[CMSampleBuffer]` array has to be extracted from the `assetTrack` at all makes this solution very slow and also puts a lot of stress on memory. Its not a good solution. I want to stay away from `CMSampleBuffer` entirely. But if nothing else works out this would probably be the only way to go. –  May 13 '17 at 17:43
  • Oh I see, you don't want to process the whole file first. I missed that. – Rhythmic Fistman May 13 '17 at 23:18

1 Answers1

0

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:

Mick
  • 24,231
  • 1
  • 54
  • 120
  • Thanks for the suggestion Mick , I will look into it and come back with a working example if all goes as expected. –  May 12 '17 at 17:25