Help us understand the problem. What is going on with this article?

AVAssetTrackの向き判定を調べたのでメモ(画面録画も)

More than 1 year has passed since last update.

画面録画機能も増えて、動画の向き判定がさらに増えたのでメモ。

AVMutableVideoCompositionLayerInstructionsetCropRectangleで切り出す時とか考慮が必要なのでご参考にどうぞ。

extension AVAssetTrack {
    ///
    // MARK: ------------------------------ properties
    ///
    /// 動画の向き確認
    ///
    var type: String {
        if 0 < self.preferredTransform.b && self.preferredTransform.c < 0 && self.preferredTransform.tx == self.naturalSize.height {
            return "ホーム下 or フロントホーム下"
        }
        if self.preferredTransform.b < 0 && 0 < self.preferredTransform.c && self.preferredTransform.ty == self.naturalSize.width {
            return "ホーム上 or フロントホーム上"
        }
        if 0 < self.preferredTransform.a && 0 < self.preferredTransform.d && self.preferredTransform.tx == 0 && self.preferredTransform.ty == 0 {
            return "ホーム右 or フロントホーム左 or 画面録画ホーム下"
        }
        if self.preferredTransform.a < 0 && self.preferredTransform.d < 0 && self.preferredTransform.tx == self.naturalSize.width && self.preferredTransform.ty == self.naturalSize.height {
            return "ホーム左 or フロントホーム右"
        }
        if self.preferredTransform.a < 0 && self.preferredTransform.d < 0 && self.preferredTransform.tx == 0 && self.preferredTransform.ty == 0 {
            return "画面録画ホーム上"
        }
        if self.preferredTransform.b < 0 && 0 < self.preferredTransform.c && self.preferredTransform.tx == 0 && self.preferredTransform.ty == 0 {
            return "画面録画ホーム右"
        }
        if 0 < self.preferredTransform.b && self.preferredTransform.c < 0 && self.preferredTransform.tx == 0 && self.preferredTransform.ty == 0 {
            return "画面録画ホーム左"
        }
        return "不明"
    }
}

2つの動画を同時に再生できるiOS(iPhone/iPad)アプリ「MultiVideo」でも、上記分岐処理を利用して動画切り取り処理を実装しています😄
MultiVideo - 2つの動画を重ねて並べて再生 -

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away