iOS8视频维度,CMVideoDimensions返回0,0 [英] iOS8 video dimension, CMVideoDimensions returns 0,0

查看:628
本文介绍了iOS8视频维度,CMVideoDimensions返回0,0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

in iOS8 the dimension returned is 0,0

CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);

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

This was working on iOS7, so how to know the supported video dimension, as i need to know the video aspect ratio

推荐答案

您需要等待 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;
        }

    }

}

这篇关于iOS8视频维度,CMVideoDimensions返回0,0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆