AVAssetImageGenerator returns sometimes same image from 2 successive frames

前端 未结 3 1904
北海茫月
北海茫月 2021-02-06 07:26

I\'m currently extracting every frame from a video with AVAssetImageGenerator, but sometimes it returns me successively 2 times almost the same image (they do not h

3条回答
  •  灰色年华
    2021-02-06 08:00

    Please see the following properties of AVAssetImageGenerator. You should set kCMTimeZero for both properties to get the exact frames.

    /* The actual time of the generated images will be within the range [requestedTime-toleranceBefore, requestedTime+toleranceAfter] and may differ from the requested time for efficiency.
       Pass kCMTimeZero for both toleranceBefore and toleranceAfter to request frame-accurate image generation; this may incur additional decoding delay.
       Default is kCMTimePositiveInfinity. */
    @property (nonatomic) CMTime requestedTimeToleranceBefore NS_AVAILABLE(10_7, 5_0);
    @property (nonatomic) CMTime requestedTimeToleranceAfter NS_AVAILABLE(10_7, 5_0);
    

    Before I set kCMTimeZero for both properties, I got some same images for different request time as you experienced. Just try the following code.

    self.imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:myAsset];
    self.imageGenerator.requestedTimeToleranceBefore = kCMTimeZero;
    self.imageGenerator.requestedTimeToleranceAfter = kCMTimeZero;
    

提交回复
热议问题