gpt4 book ai didi

objective-c - AVCaptureSession 启动内存警告

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

每次我启动 AVCaptureSession 时,我都会收到一条内存警告,导致一段时间后崩溃。
我正在异步启动 session ,Instruments 工具显示应用程序消耗了大约 2 MB 的内存。你知道如何克服这个问题吗?分配的 2MB 内存太多了吗?

谢谢![iOS 4.3,ARC]

@autoreleasepool {
//Init capture session
session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetPhoto;


//Resize container view
CGRect cameraContainerFrame = cameraContainerView.frame;
cameraContainerFrame.size = CGSizeMake(320, 426);
cameraContainerView.frame = cameraContainerFrame;

CALayer *viewLayer = [cameraContainerView layer];
[viewLayer setMasksToBounds:YES];

//Create preview layer
captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

CGRect bounds = [cameraContainerView bounds];
[captureVideoPreviewLayer setFrame:bounds];


if ([captureVideoPreviewLayer isOrientationSupported]) {
[captureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
}
[captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

[viewLayer addSublayer:captureVideoPreviewLayer];

//Get input device
captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

if ([captureDevice lockForConfiguration:nil]){
captureDevice.focusMode = AVCaptureFocusModeContinuousAutoFocus;
captureDevice.whiteBalanceMode = AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance;
[captureDevice unlockForConfiguration];
}

NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];
if (!input) {
// Handle the error appropriately.
DLog(@"ERROR: trying to open camera: %@", error);
}
//Add input to session
[session addInput:input];

//Output
stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [NSDictionary dictionaryWithObject:AVVideoCodecJPEG forKey:AVVideoCodecKey];
[stillImageOutput setOutputSettings:outputSettings];
[session addOutput:stillImageOutput];

//Save state
cameraSessionInitialized = YES;
[session startRunning];
}

最佳答案

session.sessionPreset = AVCaptureSessionPresetMedium;

如果您不关心质量,这确实可以消除内存警告。我正在尝试弄清楚如何让它与 AVCaptureSessionPresetPhoto 一起工作。

关于objective-c - AVCaptureSession 启动内存警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10056746/

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