gpt4 book ai didi

iphone - 用于音频和视频组合的 AVCaptureSession - 音频部分提供 EXC_BAD_ACCESS

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

我做了一个很棒的小应用程序,叫做 Night Cam,它可以录制夜视效果视频。我目前正在更新它。

视频捕获绝对正常,但音频却不行。当没有记录到文件时,我一打开应用程序就会出现问题(我将其更改为仅在稍后记录时激活音频)。

相关代码如下:

session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetMedium;
camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
microphone = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput * camera_input = [AVCaptureDeviceInput deviceInputWithDevice:camera error:nil];
[session addInput:camera_input];
AVCaptureDeviceInput * microphone_input = [AVCaptureDeviceInput deviceInputWithDevice:microphone error:nil];
[session addInput:microphone_input];
AVCaptureVideoDataOutput * output = [[AVCaptureVideoDataOutput alloc] init];
output.videoSettings = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
[session addOutput:output];
output.minFrameDuration = CMTimeMake(1,30);
dispatch_queue_t queue = dispatch_queue_create("MY QUEUE", NULL);
[output setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);
AVCaptureAudioDataOutput * audio_output = [[AVCaptureAudioDataOutput alloc] init];
[session addOutput:audio_output];
queue = dispatch_queue_create("MY QUEUE", NULL);
AudioOutputBufferDelegate * special_delegate = [[[AudioOutputBufferDelegate alloc] init] autorelease];
special_delegate->normal_delegate = self;
[audio_output setSampleBufferDelegate:special_delegate queue:queue];
dispatch_release(queue);

“特别代表”是这样的:

 @implementation AudioOutputBufferDelegate
-(void)captureOutput: (AVCaptureOutput *) captureOutput didOutputSampleBuffer: (CMSampleBufferRef) sampleBuffer fromConnection: (AVCaptureConnection *) conenction{
if (normal_delegate->recording) {
[normal_delegate->audio_writer_input appendSampleBuffer: sampleBuffer];
}
}
@end

记录 bool 值未设置,因此未附加任何内容。您也不必担心 AVAssestWriter 的设置,因为它在应用程序崩溃时根本没有设置。我必须是音频输入的设置。

这是崩溃时的调用堆栈:

> #0    0x33479464 in objc_msgSend
> #1 0x348154b2 in -[AVCaptureAudioDataOutput _AVCaptureAudioDataOutput_AudioDataBecameReady]
> #2 0x34815690 in AVCaptureAudioDataOutput_AudioDataBecameReady
> #3 0x33cc5984 in FigRecorderRemoteCallbacksServer_SampleBuffersArePending
> #4 0x33cc2adc in _XSampleBuffersArePending
> #5 0x33ca42ba in figrecordercallbacks_server
> #6 0x33ca3238 in remrec_ClientPortCallBack
> #7 0x33a5dbe6 in __CFMachPortPerform
> #8 0x33a556fe in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__
> #9 0x33a556c2 in __CFRunLoopDoSource1
> #10 0x33a47f7c in __CFRunLoopRun
> #11 0x33a47c86 in CFRunLoopRunSpecific
> #12 0x33a47b8e in CFRunLoopRunInMode
> #13 0x33b0e4aa in GSEventRunModal
> #14 0x33b0e556 in GSEventRun
> #15 0x32099328 in -[UIApplication _run]
> #16 0x32096e92 in UIApplicationMain
> #17 0x000023e0 in main at main.m:14

感谢您的帮助。

最佳答案

听起来您的程序正在访问某种错误的内存。您是否尝试在您的设置中启用 NSZombieEnabled 属性?我上周发现了一个类似 EXC_BAD_ACCESS 的问题。当您这样做时,它应该会在导致崩溃的调用处中断。

关于iphone - 用于音频和视频组合的 AVCaptureSession - 音频部分提供 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5188752/

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