Search code examples
cocoa-touchios8

iOS8 video dimension, CMVideoDimensions returns 0,0


in iOS8 the dimension returned is 0,0

CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);

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


Solution

  • You need to wait for the 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;
            }
    
        }
    
    }