使用AVCaptureSession录制的视频帧

时间:2013-05-20 13:12:57

标签: iphone ios avcapturesession video-recording

在我的应用程序中,我使用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];

//初始化

3 个答案:

答案 0 :(得分: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);

}

希望这对你的帮助是我的朋友

答案 1 :(得分: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;

            }

答案 2 :(得分:0)

 if ([self.captureSession canSetSessionPreset:AVCaptureSessionPreset320*568]) 
    {
        [self.captureSession setSessionPreset:AVCaptureSessionPreset320*568];
    }

尝试这个。