AFathi / ARVideoKit

Capture & record ARKit videos 📹, photos 🌄, Live Photos 🎇, and GIFs 🎆.
Apache License 2.0
1.62k stars 226 forks source link

Wrong aspect ratio for initial video recording on on iPhone 12 #124

Closed mattbierner closed 3 years ago

mattbierner commented 3 years ago

On an iPhone 12 in portrait mode, I've found that my app's first video recording will be the wrong aspect ratio.

Here's a still from the first video in the app:

Screen Shot 2020-12-08 at 12 25 09 AM

The video is 1440 × 1920

And here's the second video recorded in the app:

Screen Shot 2020-12-08 at 12 25 18 AM

This video is 664 × 1440 (which is the correct size)

As far as I can tell, the view is identical in both cases

Here's my RecordAR configuration:

private var recorder: RecordAR?

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    let recorder = RecordAR(ARSceneKit: sceneView)!
    recorder.videoOrientation = .alwaysPortrait
    recorder.contentMode = .viewAspectRatio
    recorder.enableAudio = false
    recorder.inputViewOrientations = [.portrait]
    recorder.requestMicPermission = .manual
    recorder.prepare(self.configuration)

    self.recorder = recorder
}

I've tried various other settings for content mode, but none seem to fix the first recording.

Workaround

As a workaround, I currently create a fake recording before triggering the real recording:

    // The aspect ratio gets messed up on the first recording, so trigger
    // a fake recording to fix it
    Timer.scheduledTimer(withTimeInterval: 1, repeats: false, block: { _ in
        recorder.record(forDuration: 0.5) { _ in
            recorder.enableAudio = true
        }
    })

Not sure if there's a better way to do this

mattbierner commented 3 years ago

Ah looks like swift package manager was picking up a build from back in February by default. After updating to the latest swift_5 branch, I haven't seen this again