Skip to content

Instantly share code, notes, and snippets.

@ivanlesko
Created March 7, 2016 19:13
Show Gist options
  • Save ivanlesko/2ff0695e18f15ae08c55 to your computer and use it in GitHub Desktop.
Save ivanlesko/2ff0695e18f15ae08c55 to your computer and use it in GitHub Desktop.
func configureSlomoCaptureFormats(formats: [AVCaptureDeviceFormat]) {
var bestFormat: AVCaptureDeviceFormat?
var bestFrameRateRange: AVFrameRateRange?
for format in device.formats as! [AVCaptureDeviceFormat] {
// We only want to use 420f media sub types to get the best dynamic range.
let mediaSubtype = CMFormatDescriptionGetMediaSubType(format.formatDescription)
if mediaSubtype == k420f {
// let dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription)
let ranges = format.videoSupportedFrameRateRanges as! [AVFrameRateRange]
let range = ranges.first!
let someFormat = CameraFormat(format: format, range: range)
print(someFormat)
for range in format.videoSupportedFrameRateRanges as! [AVFrameRateRange] {
if bestFormat == nil {
bestFormat = format
bestFrameRateRange = range
}
if range.maxFrameRate > bestFrameRateRange?.maxFrameRate {
bestFormat = format
bestFrameRateRange = range
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment