2

在我 AVCaptureSession用来记录的应用程序中video

录制完成后,我得到的视频大小360 X 480

我已将记录层大小设置为320 X 568.

我错过了一些东西,我试过但没有得到。

谁能指导我在哪里更改以获取video大小为的录音320 X 568

这是我的代码,

初始化

AVCaptureDevice* device = nil;
AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
captureOutput.alwaysDiscardsLateVideoFrames = YES; 



dispatch_queue_t queue;
queue = dispatch_queue_create("cameraQueue", NULL);
[captureOutput setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);

// 设置视频输出到 BGRA 中存储帧

NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; 
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; 
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key]; 
[captureOutput setVideoSettings:videoSettings]; 

//然后我们创建一个捕获会话

self.captureSession = [[AVCaptureSession alloc] init];
self.captureSession.sessionPreset = AVCaptureSessionPresetMedium;

if([self.captureSession respondsToSelector:@selector(addInput:)])
        [self.captureSession addInput:captureInput];
    if([self.captureSession respondsToSelector:@selector(addOutput:)])
        [self.captureSession addOutput:captureOutput];

/*We add the Custom Layer (We need to change the orientation of the layer so that the video is displayed correctly)*/
self.customLayer = [CALayer layer];
self.customLayer.frame = self.view.bounds;

self.customLayer.transform = CATransform3DRotate(CATransform3DIdentity, M_PI/2.0f, 0, 0, 1);
    self.customLayer.transform = CATransform3DScale(self.customLayer.transform,.7,.7,1);
    self.customLayer.transform = CATransform3DTranslate(self.customLayer.transform,-23,0,0);

self.customLayer.contentsGravity = kCAGravityResizeAspectFill;
[self.view.layer addSublayer:self.customLayer];
[self.captureSession startRunning];

//初始化结束

4

3 回答 3

1

AvCaptureSessionMedium 不允许您使用 320 * 568 的图像分辨率。AVCaptureSession 中没有为此分辨率设置属性。

AVCaptureSessionPresetMedium 使用的相机分辨率为 360.000000 和 480.000000。这是 AVCaptureSessionPresetMedium 的默认分辨率,因此它不适用于 iPhone-5 显示器。

如果你想在 iPhone-5 上获得更高分辨率的图像,你应该使用 AVCaptureSessionPresetHigh。但它会为您提供 1980 * 1080 的图像分辨率。所以它可以正常工作,但会增加图像的大小字节。

您也可以通过以下方式检查:

 AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init];    

     if (IS_IPHONE5) 
    {          
               newCaptureSession.sessionPreset = AVCaptureSessionPresetHigh; 
    }
    else
            {
           newCaptureSession.sessionPreset = AVCaptureSessionPresetMedium;

            }
于 2014-02-04T07:12:32.477 回答
1

您能否在这行代码之前尝试检查是否self.customLayer.frame = self.view.bounds;为 iphone5。如果是,则手动设置其框架,例如

你可以检查: -

#define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE

//We add the Custom Layer (We need to change the orientation of the layer so that the video is displayed correctly)*/

self.customLayer = [CALayer layer];


if(isIphone5)
{
self.customLayer.frame = CGRectMake(0, 0, 320, 568);
}
else
{
self.customLayer.frame = CGRectMake(0, 0, 320, 480);

}

希望这对你有帮助

于 2013-05-20T14:04:36.017 回答
0
 if ([self.captureSession canSetSessionPreset:AVCaptureSessionPreset320*568]) 
    {
        [self.captureSession setSessionPreset:AVCaptureSessionPreset320*568];
    }

try this one.

于 2013-05-20T13:16:19.290 回答