Skip to content

Instantly share code, notes, and snippets.

@kb100824
Forked from Limon-O-O/BrightnessValue.swift
Created August 16, 2023 06:52
Show Gist options
  • Save kb100824/51321aaf6520adb76580f0c7041632a2 to your computer and use it in GitHub Desktop.
Save kb100824/51321aaf6520adb76580f0c7041632a2 to your computer and use it in GitHub Desktop.
get brightness value from CMSampleBuffer
func getBrightnessValue(from sampleBuffer: CMSampleBuffer) -> Float {
guard
let metadataDict = CMCopyDictionaryOfAttachments(nil, sampleBuffer, kCMAttachmentMode_ShouldPropagate) as? [String: Any],
let exifMetadata = metadataDict[String(kCGImagePropertyExifDictionary)] as? [String: Any],
let brightnessValue = exifMetadata[String(kCGImagePropertyExifBrightnessValue)] as? Float
else { return 0.0 }
return brightnessValue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment