gpt4 book ai didi

iphone - 使用 AVCaptureSession 录制的视频帧

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:13:53 25 4
gpt4 key购买 nike

在我的应用程序中,我使用 AVCaptureSession 来录制 video

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

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

我遗漏了一些东西,我试过了但没有找到。

任何人都可以指导我应该在哪里更改以录制大小为 320 X 568video

这是我的代码,

初始化

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];

//然后我们创建一个捕获 session

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];

//初始化结束

最佳答案

你能不能在这行 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);

}

希望这对你有帮助,我的 friend

关于iphone - 使用 AVCaptureSession 录制的视频帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16650356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com