【问题标题】:Recorded video Frame using AVCaptureSession使用 AVCaptureSession 录制的视频帧
【发布时间】:2013-05-20 13:12:57
【问题描述】:

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

//初始化结束

【问题讨论】:

  • 使用VideoSettings 属性。
  • 确保你不会忘记添加 iphone5 Default-568h@2x.png
  • @Nitin,是的,我添加了 Default-568h@2x.png
  • 好的,那么我希望您正确检查其设备是否为 iphone5 是否正确..?如果是,那么您还将图层大小设置为标准设备,所以请您与您的问题分享此代码,那么您可以理解您的内容
  • 是的,检查正确。并且在 3.5" 屏幕中也给出相同的尺寸 360 X 480。我已经检查了更改图层大小但没有更改。添加有问题的代码。

标签: iphone ios avcapturesession video-recording


【解决方案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);

}

希望这对你有帮助

【讨论】:

  • 感谢回复 是的,我已经这样做了。但没有得到任何改变。
【解决方案2】:

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;

            }

【讨论】:

    【解决方案3】:
     if ([self.captureSession canSetSessionPreset:AVCaptureSessionPreset320*568]) 
        {
            [self.captureSession setSessionPreset:AVCaptureSessionPreset320*568];
        }
    

    试试这个。

    【讨论】:

    • 这个选项在哪里?AVCaptureSessionPreset320*568。它给出错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-08
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2012-03-19
    • 2012-02-28
    相关资源
    最近更新 更多