cocoa-touch - iOS8视频尺寸,CMVideoDimensions返回0,0

标签 cocoa-touch ios8

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

CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);

这是在 iOS7 上工作的,所以如何知道支持的视频尺寸,因为我需要知道视频宽高比

最佳答案

您需要等待AVCaptureInputPortFormatDescriptionDidChangeNotification

- (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;
        }

    }

}

关于cocoa-touch - iOS8视频尺寸,CMVideoDimensions返回0,0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25902122/

相关文章:

swift - 如何在 Swift viewDidLoad 中获取邮政编码?

ios - WKWebView 和 NSURLProtocol 不工作

在 Swift 中旋转设备时 iOS 8 tableview 单元格高度发生变化

ios - 为可调整大小的 UIView 设置最小和最大宽度和高度

ios - 用 Dictionary 类型的参数声明的函数显示另一个参数类型

xcode - 显示评分星星 xcode

ios - 将导航栏的背景图像恢复为默认值

cocoa-touch - 是否有必要始终在 block 内使用对 self 的弱引用..?

ios - UITableViewCell 中图像的动态帧计算

ios - 在没有导航 Controller 的情况下向代码中的 View 添加导航栏