gpt4 book ai didi

objective-c - QTKit,打开输入设备?

转载 作者:行者123 更新时间:2023-12-03 18:07:06 26 4
gpt4 key购买 nike

我正在尝试向 QTCaptureSession 添加两个输入,如下所示:

mainSession = [[QTCaptureSession alloc] init];

BOOL success;
NSError* error;

QTCaptureDevice *videoDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:@"QTMediaTypeVideo"];
success = [videoDevice open:&error];

QTCaptureDevice *audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:@"QTMediaTypeSound"];
success = [audioDevice open:&error];

//video = [[QTCaptureDeviceInput alloc] initWithDevice:videoDevice];
//success = [mainSession addInput:video error:&error];

//audio = [[QTCaptureDeviceInput alloc] initWithDevice:audioDevice];
//success = [mainSession addInput:audio error:&error];

output = [[QTCaptureMovieFileOutput alloc] init];
success = [mainSession addOutput:output error:&error];

[output setDelegate:self];

[movieView setCaptureSession:mainSession];

[mainWindow makeKeyAndOrderFront:NSApp];

[mainSession startRunning];

我确定注释掉的部分是错误的来源:

[QTCaptureDeviceInput initWithDevice:]- cannot intialize device input with device that is not open.

我在开放方法之后探测了我的“成功”变量,结果是肯定的。那么为什么该方法认为设备未打开呢?

最佳答案

如果您还没有找到答案,我认为您的问题实际上是在您指出的两行上方。我检查了 Apple 的文档,发现 QTMediaTypeSound 和 QTMediaTypeVideo 是常量,而不是您应该手动传入的字符串。例如,快速的 NSLog() 语句显示 QTMediaTypeVideo 常量实际上等于“vide”。

简而言之,您的代码应该是:

mainSession = [[QTCaptureSession alloc] init];

BOOL success;
NSError* error;

QTCaptureDevice *videoDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo];
success = [videoDevice open:&error];

QTCaptureDevice *audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeSound];
success = [audioDevice open:&error];

video = [[QTCaptureDeviceInput alloc] initWithDevice:videoDevice];
success = [mainSession addInput:video error:&error];

audio = [[QTCaptureDeviceInput alloc] initWithDevice:audioDevice];
success = [mainSession addInput:audio error:&error];

output = [[QTCaptureMovieFileOutput alloc] init];
success = [mainSession addOutput:output error:&error];

[output setDelegate:self];

[movieView setCaptureSession:mainSession];

[mainWindow makeKeyAndOrderFront:NSApp];

[mainSession startRunning];

关于objective-c - QTKit,打开输入设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/628465/

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