Generate images from AVAssetImageGenerator gives same image duplicates for different times

前端 未结 1 1666
梦谈多话
梦谈多话 2021-01-20 16:05

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

1条回答
  •  后悔当初
    2021-01-20 16:49

    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)
    

    0 讨论(0)
提交回复
热议问题