Cocoa touch iOS8视频维度,CMVideoDimensions返回0,0

Cocoa touch iOS8视频维度,CMVideoDimensions返回0,0,cocoa-touch,ios8,Cocoa Touch,Ios8,在iOS8中,返回的维度为0,0 CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription); 这是在iOS7上进行的,因此如何知道支持的视频维度,因为我需要知道视频纵横比您需要等待AVCaptureInputPortFormatDescriptionIDChangeNotification - (void)avCaptureInputPortFormatDescriptionD

在iOS8中,返回的维度为0,0

CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);

这是在iOS7上进行的,因此如何知道支持的视频维度,因为我需要知道视频纵横比

您需要等待AVCaptureInputPortFormatDescriptionIDChangeNotification

- (void)avCaptureInputPortFormatDescriptionDidChangeNotification:(NSNotification *)notification {

    AVCaptureInput *input = [self.recorder.captureSession.inputs objectAtIndex:0];
    AVCaptureInputPort *port = [input.ports objectAtIndex:0];
    CMFormatDescriptionRef formatDescription = port.formatDescription;
    if (formatDescription) {
        CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
        if ((dimensions.width == 0) || (dimensions.height == 0)) {
            return;
        }
        CGFloat aspect = (CGFloat)dimensions.width / (CGFloat)dimensions.height;

        if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
            // since iOS8 the aspect ratio is inverted
            // remove this check if iOS7 will not be supported
            aspect = 1.f / aspect;
        }

    }

}

如果您正在跟踪正在使用的设备,您可以从
activeFormat

访问当前格式。我最近遇到了这一特定问题,以下是Swift 5版本,供需要它的人使用:

<代码>导入基础 进口AVF基金会 类MySessionManager:NSObject{ 静态let notificationName=“AvCaptureInputPortFormatDescriptionIDChangeNotification” let会话:AVCaptureSession var videoCaptureDimensions:CMVideoDimensions? 初始化(会话:AVCaptureSession){ self.session=会话 让notificationName=NSNotification.Name() NotificationCenter.default.addObserver( 自己 选择器:#选择器(formatDescription(didChange:), 名称:.init(Self.notificationName), 对象:无 ) } deinit{NotificationCenter.default.removeObserver(self)} @objc func formatDescription(didChange通知:NSNotification){ 警卫 让输入=session.inputs.first, 让port=input.ports.first, 让formatDesc=port.formatDescription else{return} 变量维度=CMVideoFormatDescriptionGetDimensions(FormatDescription) //…执行任何必要的调光。。。 视频捕获尺寸=尺寸 } }
您不能只检查当前设备上的
activeFormat
属性吗?