🎉
(Swift)RPBroadcastSampleHandlerのprocessSampleBufferに渡される画像の向きを取得する方法
結論
ReplayKitの話題です。processSampleBufferに渡されるCMSampleBufferには画像の向きを示すプロパティが定義されていません。この問題を解決するにはRPVideoSampleOrientationKeyで画像の向きを取得します。
if let orientationAttachment = CMGetAttachment(
sampleBuffer, key: RPVideoSampleOrientationKey as CFString, attachmentModeOut: nil) as? NSNumber
{
let orientation = CGImagePropertyOrientation(rawValue: orientationAttachment.uint32Value)
}
(おまけ)CGImagePropertyOrientationの値一覧
| CGImagePropertyOrientation | rawValue |
|---|---|
| .up | 1 |
| .upMirrored | 2 |
| .down | 3 |
| .downMirrored | 4 |
| .leftMirrored | 5 |
| .right | 6 |
| .rightMirrored | 7 |
| .left | 8 |
Discussion