I am trying to generate thumbnail images from a video using the following code. It does generate UIImages but the images are all the same at different time. For example, for
By default AVAssetImageGenerator
gives itself very generous tolerances when fetching frames for a given time. If you use copyCGImage
's actualTime
you'll see in practice that it's something like one or two seconds, although technically it's kCMTimeFlags_PositiveInfinity
, so in your short video half of your frames will be duplicates.
So set the tolerances to something smaller to see unique frames:
imageGenerator.requestedTimeToleranceBefore = CMTimeMake(1, 15)
imageGenerator.requestedTimeToleranceAfter = CMTimeMake(1, 15)