             if let dimensions = self.dimensions {
                 config[AVVideoWidthKey] = NSNumber(integerLiteral: Int(dimensions.width))
                 config[AVVideoHeightKey] = NSNumber(integerLiteral: Int(dimensions.height))
-            } else if let buffer = sampleBuffer {
-                if let formatDescription: CMFormatDescription = CMSampleBufferGetFormatDescription(buffer) {
-                    let videoDimensions = CMVideoFormatDescriptionGetDimensions(formatDescription)
+            } else if let buffer = sampleBuffer,
+                      let formatDescription: CMFormatDescription = CMSampleBufferGetFormatDescription(buffer) {
+                let videoDimensions = CMVideoFormatDescriptionGetDimensions(formatDescription)
+                switch self.aspectRatio {
+                case .standard:
+                    config[AVVideoWidthKey] = NSNumber(integerLiteral: Int(videoDimensions.width))
+                    config[AVVideoHeightKey] = NSNumber(integerLiteral: Int(videoDimensions.width * 3 / 4))
+                    break
+                case .widescreen:
+                    config[AVVideoWidthKey] = NSNumber(integerLiteral: Int(videoDimensions.width))
+                    config[AVVideoHeightKey] = NSNumber(integerLiteral: Int(videoDimensions.width * 9 / 16))
+                    break
+                case .square:
+                    let min = Swift.min(videoDimensions.width, videoDimensions.height)
+                    config[AVVideoWidthKey] = NSNumber(integerLiteral: Int(min))
+                    config[AVVideoHeightKey] = NSNumber(integerLiteral: Int(min))
+                    break
+                case .active:
+                    fallthrough
+                default:
                     config[AVVideoWidthKey] = NSNumber(integerLiteral: Int(videoDimensions.width))
                     config[AVVideoHeightKey] = NSNumber(integerLiteral: Int(videoDimensions.height))
+                    break
                 }
             }
 

/// NextLevelVideoConfiguration, video capture configuration object
public class NextLevelVideoConfiguration: NextLevelConfiguration {

    /// Average video bit rate (bits per second), AV dictionary key AVVideoAverageBitRateKey
    public var bitRate: Int

    /// Dimensions for video output, AV dictionary keys AVVideoWidthKey, AVVideoHeightKey
    public var dimensions: CGSize?

    /// Video output transform for display
    public var transform: CGAffineTransform

    
    override init() {
        self.bitRate = NextLevelVideoConfigurationDefaultBitRate
        self.aspectRatio = .active
        self.transform = CGAffineTransform.identity
        self.codec = AVVideoCodecH264
        self.scalingMode = AVVideoScalingModeResizeAspectFill
