//插件对象
@interface SampleHandler : RPBroadcastSampleHandler
//重写方法
- (void)processSampleBuffer:(CMSampleBufferRef)sampleBuffer withType:(RPSampleBufferType)sampleBufferType;
//获取影像方向信息
CFStringRef RPVideoSampleOrientationKeyRef = (__bridge CFStringRef)RPVideoSampleOrientationKey;
NSNumber *orientation = (NSNumber *)CMGetAttachment(sampleBuffer, RPVideoSampleOrientationKeyRef,NULL);
NSLog(@"info:%@", orientation);
枚举
/* Possible int values for kCGImagePropertyTIFFOrientation */
typedef CF_ENUM(uint32_t, CGImagePropertyOrientation) {
kCGImagePropertyOrientationUp = 1, // 0th row at top, 0th column on left - default orientation
kCGImagePropertyOrientationUpMirrored, // 0th row at top, 0th column on right - horizontal flip
kCGImagePropertyOrientationDown, // 0th row at bottom, 0th column on right - 180 deg rotation
kCGImagePropertyOrientationDownMirrored, // 0th row at bottom, 0th column on left - vertical flip
kCGImagePropertyOrientationLeftMirrored, // 0th row on left, 0th column at top
kCGImagePropertyOrientationRight, // 0th row on right, 0th column at top - 90 deg CW
kCGImagePropertyOrientationRightMirrored, // 0th row on right, 0th column on bottom
kCGImagePropertyOrientationLeft // 0th row on left, 0th column at bottom - 90 deg CCW
};
直播旋转角度:
/**获取影像的方向 计算需旋转角度 1 —— */
-(CGFloat)getRotateByBuffer:(CMSampleBufferRef)sampleBuffer{
CGFloat rotate = 270;
if (@available(iOS 11.1, *)) {
/*
1.1以上支持自动旋转
IOS 11.0系统 编译RPVideoSampleOrientationKey会bad_address
Replaykit bug:api说ios 11 支持RPVideoSampleOrientationKey 但是 却存在bad_address的情况 代码编译执行会报错bad_address 即使上面@available(iOS 11.1, *)也无效
解决方案:Link Binary With Libraries -->Replaykit Request-->Option
*/
CFStringRef RPVideoSampleOrientationKeyRef = (__bridge CFStringRef)RPVideoSampleOrientationKey;
NSNumber *orientation = (NSNumber *)CMGetAttachment(sampleBuffer, RPVideoSampleOrientationKeyRef,NULL);
// 如果影像未转变 获取到的是nil
if (orientation == nil && self.lastOrientation) {
orientation = self.lastOrientation;
}
self.lastOrientation = orientation;
switch ([orientation integerValue]) {
//竖屏时候
//SDK内部会做图像大小自适配(不会变形) 所以上层只要控制横屏时候的影像旋转的问题
case kCGImagePropertyOrientationUp:{
rotate = 0;
}
break;
case kCGImagePropertyOrientationDown:{
rotate = 180;
break;
}
case kCGImagePropertyOrientationLeft: {
//静音键那边向上 所需转90度
rotate = 90;
}
break;
case kCGImagePropertyOrientationRight:{
//关机键那边向上 所需转270
rotate = 270;
}
break;
default:
break;
}
}
return rotate;
}
iOS11.0真机调试异常:
dyld: Symbol not found: _RPVideoSampleOrientationKey
解决方案:
Link Binary With Libraries -->Replaykit Request-->Option
备注原文链接:https://blog.csdn.net/linpeng_1/article/details/83582521