Cocoa QTKit和录制电影 [英] Cocoa QTKit and recording movies

查看:199
本文介绍了Cocoa QTKit和录制电影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是全新的QTKit,我正在寻找一些反馈下面的代码,我试图用来显示相机的图像和录制电影。

I'm new with the whole QTKit and I was looking for some feedback on the following code that I am attempting to use to display the camera's image and record movies.

- (void)initializeMovie {

NSLog(@"Hi!");

QTCaptureSession* mainSession = [[QTCaptureSession alloc] init];

QTCaptureDevice* deviceVideo = [QTCaptureDevice defaultInputDeviceWithMediaType:@"QTMediaTypeVideo"];

QTCaptureDevice* deviceAudio = [QTCaptureDevice defaultInputDeviceWithMediaType:@"QTMediaTypeSound"];

NSError* error;

[deviceVideo open:&error];
[deviceAudio open:&error];

QTCaptureDeviceInput* video = [QTCaptureDeviceInput deviceInputWithDevice:deviceVideo];

QTCaptureDeviceInput* audio = [QTCaptureDeviceInput deviceInputWithDevice:deviceAudio];

[mainSession addInput:video error:&error];
[mainSession addInput:audio error:&error];

QTCaptureMovieFileOutput* output = [[QTCaptureMovieFileOutput alloc] init];
[output recordToOutputFileURL:[NSURL URLWithString:@"Users/chasemeadors/Desktop/capture1.mov"]];

[mainSession addOutput:output error:&error];

[movieView setCaptureSession:mainSession];

[mainSession startRunning];

}

另外,我不确定整个错误参数方法继续调用,我在一个示例中看到&错误符号,但我不知道它的意思。

Also, I'm not sure about the whole error parameter that the methods keep calling for, I saw the "&error" symbol in an example but I don't know what it means.

当我明确打开设备时,错误无法初始化未打开的设备。

I'm also getting an error "cannot initialize a device that is not open" when I explicitly open the devices.

如果任何人可以帮我解决这个问题,那将是一个很大的帮助。

If anyone could help me sort this out, it'd be a great help, thanks.

推荐答案


QTCaptureDevice * deviceVideo = [QTCaptureDevice defaultInputDeviceWithMediaType:@QTMediaTypeVideo];

QTCaptureDevice* deviceVideo = [QTCaptureDevice defaultInputDeviceWithMediaType:@"QTMediaTypeVideo"];

QTCaptureDevice * deviceAudio = QTCaptureDevice defaultInputDeviceWithMediaType:@QTMediaTypeSound];

QTCaptureDevice* deviceAudio = [QTCaptureDevice defaultInputDeviceWithMediaType:@"QTMediaTypeSound"];

在这里传递实际常量,而不是包含其名称的字符串文字。不能保证 QTMediaTypeVideo 定义为 @QTMediaTypeVideo;它可以随时更改。 p>

Pass the actual constants here, not string literals containing their names. There's no guarantee that QTMediaTypeVideo is defined to @"QTMediaTypeVideo"; it could be @"Ollie ollie oxen free", and even if it is what you expect now, it could change at any time.


[output recordToOutputFileURL:[NSURL URLWithString:@"Users/chasemeadors/Desktop/capture1.mov"]];


不要假定当前工作目录是/。始终使用绝对路径。 (我知道这是测试代码;在实际代码中,当然,你将运行一个NSSavePanel并获得从那里的路径。)

Don't assume that the current working directory is /. Always use absolute paths. (I know this is test code; in real code, of course, you would have run an NSSavePanel and gotten the path from there.)


另外,我不确定的方法不断调用的整个错误参数,我看到&错误一个例子中的符号,但我不知道它的含义。

Also, I'm not sure about the whole error parameter that the methods keep calling for, I saw the "&error" symbol in an example but I don't know what it means.

意味着你获取一个变量的地址,在这种情况下错误。你将这个地址(a.k.a.指针)传递给QTKit方法之一的错误:参数。如果遇到错误,该方法将创建一个NSError对象并将其存储在该地址,即在您的变量中。这被称为通过引用返回(引用是您提供的指针)。

The & means you're taking the address of a variable, which in this case is error. You're passing this address (a.k.a. pointer) to the error: argument of one of QTKit's methods. The method will, if it encounters an error, create an NSError object and store it at that address—i.e., in your variable. This is called "return-by-reference" (the "reference" being the pointer you provided).


I'm also getting an error "cannot initialize a device that is not open" when I explicitly open the devices.

哪一种方法会返回错误?错误无法初始化未打开的设备你在谈论NSError,还是只是一个控制台消息?如果是后者,检查你的NSError变量,看看什么是留下的问题方法。

Which method returns the error? Are you talking about an NSError, or just a Console message? If the latter, check your NSError variable and see what the problem method left behind.

顺便说一下,这是为什么你应该释义,如果任何QTKit方法返回一个错误:其中一个后续邮件可能会出现新错误,如果您不这样做。

This, incidentally, is why you should bail out if any of the QTKit methods returns an error: one of the subsequent messages may clobber it with a new error if you don't.

这篇关于Cocoa QTKit和录制电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆