Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 372
Peter Lapisu Avatar asked Oct 24 '25 01:10

Peter Lapisu


1 Answers

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

    }

}
like image 163
Peter Lapisu Avatar answered Oct 29 '25 01:10

Peter Lapisu