0
1

More than 1 year has passed since last update.

preferredVideoStabilizationModeが効かないのだが????

Last updated at Posted at 2023-03-03

動画を撮影するようなコードを書くときに、手ぶれ補正をつけたくて調べていると
「ほう、AVCaptureConnection.preferredVideoStabilizationModeを設定すればええんやな」
ということで雑に

output.connection(with: .video)?.preferredVideoStabilizationMode = .auto

と設定してみたところ体感効いていなかったので

device.activeFormat.isVideoStabilizationModeSupported(_):で確認してみると、.offが返ってきた。

あれれーおかしいぞーと思いながらあれこれ調べていると

Currently, only the 1080p30 and 1080p60 video formats support cinematic stabilization. The default value for preferredVideoStabilizationMode is AVCaptureVideoStabilizationModeOff. As on earlier products, only the 16:9 video formats support stabilization.

なるほど、AVCaptureDevice.Formatの解像度とfpsによって使えたり使えなかったりするのか

ということで

let format = device.formats.filter { $0.isAnyStabilizationModeSupported }
                .max(by: { $0.formatDescription.dimensions.width < $1.formatDescription.dimensions.width })

で手ぶれ補正対応のformatで最も解像度が高いものを取り出してdevice.activeFormatに突っ込むと手ぶれ補正効きました。
ちなみにiPhone14 Proで選択された解像度は3840x2160、全然1080pじゃなかった。上のリンクの情報古いのかな。

ところで上のコードのisAnyStabilizationSupportedはextensionで定義しているもので、中身は

private extension AVCaptureDevice.Format {
    var isAnyStabilizationModeSupported: Bool {
        return isVideoStabilizationModeSupported(.cinematicExtended) 
            || isVideoStabilizationModeSupported(.cinematic) 
            || isVideoStabilizationModeSupported(.standard)
    }
}

となっています。isVideoStabilizationModeSupported(.auto)でええやんwと思ったのですが、これだと.offも含まれてしまうので全てのフォーマットがtrueを返してしまうようです。

それにしても.cinematicExtendedすごいぞ。ほぼgo proやん

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1