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

Pet*_*isu 3 cocoa-touch ios8

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

CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
Run Code Online (Sandbox Code Playgroud)

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

Pet*_*isu 5

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

    }

}
Run Code Online (Sandbox Code Playgroud)

  • 您不能只使用检查当前设备上的 `activeFormat` 属性吗?https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureDevice_Class/index.html#//apple_ref/occ/instp/AVCaptureDevice/activeFormat (2认同)