CMSampleBufferの方向を取得する
ReplayKitのRPBroadcastSampleHandler
では1フレームの情報をCMSampleBufferとして受け取り、それを自由に扱うことができます。
今回はCMSampleBuffer
から方向を取得してみたいと思います。
結論からいうと下記でできます。
internal extension CMSampleBuffer { internal var orientation: CGImagePropertyOrientation { if let orientationAttachment = CMGetAttachment(self, RPVideoSampleOrientationKey as CFString, nil) as? NSNumber { if let orientation = CGImagePropertyOrientation(rawValue: orientationAttachment.uint32Value) { return orientation } } return .up } }
しかし、iOSの特定バージョン以前では RPVideoSampleOrientationKey
がリンクエラーで起動時に失敗します。
iOS 11.0 ~ NG iOS 11.1 ~ NG iOS 11.2.1 NG iOS 11.2.5 OK
という状況です。
また、
RPVideoSampleOrientationKey
の中身はRPSampleBufferVideoOrientation
なので、iOS11.0系の端末を使って下記のようにハードコードで試してみました。
しかしながら、方向の情報はnilになってしまい、取得することができませんでした。
CMGetAttachment(self, kCGImagePropertyOrientation, nil)
ダメ元で、CGImageのOrientationも試してみましたがダメ...
公式の情報を見る限りはiOS11.0~使えるはずなのですが。。。使えないじゃん(泣)という情報でした。