1

In my app I want to take frames from a video for filtering them. I try to take frame frim video by time offset. This is my code:

- (UIImage*)getVideoFrameForTime:(NSDate*)time {

    CGImageRef thumbnailImageRef = NULL;

    NSError *igError = nil;

    NSTimeInterval timeinterval = [time timeIntervalSinceDate:self.videoFilterStart];

    CMTime atTime = CMTimeMakeWithSeconds(timeinterval, 1000);
    thumbnailImageRef =
    [self.assetImageGenerator copyCGImageAtTime:atTime
                                     actualTime:NULL
                                          error:&igError];

    if (!thumbnailImageRef) {
        NSLog(@"thumbnailImageGenerationError %@", igError );
    }

    UIImage *image = thumbnailImageRef ? [[UIImage alloc] initWithCGImage:thumbnailImageRef] : nil;

    return image;
}

Unfortunately, I see only frames which located on integer seconds: 1, 2, 3.. Even when time interval is non-integer (1.5, etc).

How to get frames at any non-integer interval?

Eugene Trapeznikov
  • 3,220
  • 6
  • 47
  • 74
  • Possible duplicate of [Grab frames from video using Swift](http://stackoverflow.com/questions/32286320/grab-frames-from-video-using-swift) – shallowThought Jan 18 '17 at 15:24

3 Answers3

1

Use this project to get more frame details The corresponding project on github: iFrameExtractor.git

1

Thnx to @shallowThought I found an answer in this question Grab frames from video using Swift

You just need to add this two lines

assetImgGenerate.requestedTimeToleranceAfter = kCMTimeZero;
assetImgGenerate.requestedTimeToleranceBefore = kCMTimeZero;
Community
  • 1
  • 1
Eugene Trapeznikov
  • 3,220
  • 6
  • 47
  • 74
0

If I remember correctly NSDate's accuracy only goes up to the second which explains why frames are only take on integer seconds. You'll have to use a different type of input to get frames at non-integer seconds.

TheAmateurProgrammer
  • 9,252
  • 8
  • 52
  • 71