Search code examples
objective-cmacosavfoundationpixelrgb

Get pixel RGB value from video - Objective-C Mac


I'd like to get a specific pixel's RGB value using an X/Y coordinate from a video file.

Like, go through the video and print the current timecode (+fps) and RGB value of pixel at X/Y coordinate.

Can anyone give me a starting point for this?

I've seen a few examples using AVCaptureSession on iOS that use

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection

To convert the sampleBuffer to a CIImage and grab the pixel value from wherever...

Can this same technique be accomplished using a preexisting video file playing back?


Solution

  • Look at using AVAssetImageGenerator which will allow you to directly generate images from the video in the background.