投稿は古いですが、Google でほぼ最初のものであり、有効な回答がないため、もう 1 つのオプションがあります。
4.x から 7.x までの iOS 向けのソリューション
AV Foundation
それはすべてフレームワークの観点からです
を構成して開始すると、変数AVCaptureSession
内のビデオのサイズを見つけることができます[[[session.inputs.lastObject] ports].lastObject formatDescription]
おおよそのコードは次のとおりです。
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]);
}
iOS8向けソリューション
Apple は再びすべてを変更しました: 今すぐ購読する必要がありますAVCaptureInputPortFormatDescriptionDidChangeNotification
サンプルは次のとおりです。
-(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);
}
}