Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The post is old, but it is almost first in google, and it has got no valid answer, so here's one more option:</p> <p><strong>Solution for iOS from 4.x to 7.x</strong></p> <p>It's all in terms of <code>AV Foundation</code> framework</p> <p>After <code>AVCaptureSession</code> is configured and started you can find video dimensions inside <code>[[[session.inputs.lastObject] ports].lastObject formatDescription]</code> variable</p> <p>Here's approximate code:</p> <pre><code>AVCaptureSession* session = ...; AVCaptureDevice *videoCaptureDevice = ...; AVCaptureDeviceInput *videoInput = ...; [session beginConfiguration]; if ([session canAddInput:videoInput]) {[session addInput:videoInput];} [session commitConfiguration]; [session startRunning]; //this is the clue AVCaptureInputPort *port = videoInput.ports.lastObject; if ([port mediaType] == AVMediaTypeVideo) { videoDimensions = CMVideoFormatDescriptionGetDimensions([port formatDescription]); } </code></pre> <p><strong>Solution for iOS8</strong></p> <p>Apple did change everything again: now you must subscribe for <code>AVCaptureInputPortFormatDescriptionDidChangeNotification</code></p> <p>Here is the sample:</p> <pre><code>-(void)initSession { AVCaptureSession* session = ...; AVCaptureDevice *videoCaptureDevice = ...; AVCaptureDeviceInput *videoInput = ...; [session beginConfiguration]; if ([session canAddInput:videoInput]) {[session addInput:videoInput];} [session commitConfiguration]; [session startRunning]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(avCaptureInputPortFormatDescriptionDidChangeNotification:) name:@"AVCaptureInputPortFormatDescriptionDidChangeNotification" object:nil]; } -(void)avCaptureInputPortFormatDescriptionDidChangeNotification:(NSNotification *)notification { AVCaptureInputPort *port = [videoInput.ports objectAtIndex:0]; CMFormatDescriptionRef formatDescription = port.formatDescription; if (formatDescription) { videoDimensions = CMVideoFormatDescriptionGetDimensions(formatDescription); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload