Skip to content

Commit

Permalink
Halve framerate and dimension if they are big (#31)
Browse files Browse the repository at this point in the history
We already clamp the framerate to 5-30. Do wee need to also halve it? If so should the halving be based on the clamped value, or the original value then clamped to 5-30..?

closes #28
  • Loading branch information
LarsJK authored and sindresorhus committed Jun 12, 2018
1 parent c4f0e9d commit 6704119
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions Gifski/SavePanelAccessoryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class SavePanelAccessoryViewController: NSViewController {
/// TODO: Use KVO here

let metadata = inputUrl.videoMetadata!
let frameRate = Int(metadata.frameRate).clamped(to: 5...30)
var currentDimensions = metadata.dimensions

func estimateFileSize() {
Expand Down Expand Up @@ -50,10 +49,36 @@ final class SavePanelAccessoryViewController: NSViewController {
}

// Set initial defaults
configureScaleSlider(inputDimensions: metadata.dimensions)
configureFramerateSlider(inputFrameRate: metadata.frameRate)
configureQualitySlider()
}

private func configureScaleSlider(inputDimensions dimensions: CGSize) {
if dimensions.width >= 640 {
scaleSlider.doubleValue = 0.5
}
scaleSlider.minValue = minimumScale(inputDimensions: dimensions)
scaleSlider.triggerAction()
frameRateSlider.maxValue = Double(frameRate)
frameRateSlider.integerValue = frameRate
}

private func minimumScale(inputDimensions dimensions: CGSize) -> Double {
let shortestSide = min(dimensions.width, dimensions.height)
return 10 / Double(shortestSide)
}

private func configureFramerateSlider(inputFrameRate frameRate: Double) {
frameRateSlider.maxValue = frameRate.clamped(to: 5...30)
frameRateSlider.doubleValue = defaultFrameRate(inputFrameRate: frameRate)
frameRateSlider.triggerAction()
}

private func defaultFrameRate(inputFrameRate frameRate: Double) -> Double {
let defaultFrameRate = frameRate >= 24 ? frameRate / 2 : frameRate
return defaultFrameRate.clamped(to: 5...30)
}

private func configureQualitySlider() {
qualitySlider.doubleValue = defaults[.outputQuality]
qualitySlider.triggerAction()
}
Expand Down

0 comments on commit 6704119

Please sign in to comment.