Set resolution in QTCapture?

Set resolution in QTCapture?

秉烛思 发布于 2021-11-28 字数 362 浏览 746 回复 3 原文

I'm recording from a webcam. The camera looks great in PhotoBooth. However, when I preview it in my program with a QTCaptureView, or record it to a file, it is very, very slow. The reason is that QuickTime is giving me the maximum possible resolution of 1600x1200. How can I force a more reasonable size for both my QTCaptureView and my recording to file?

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦开始←不甜 2022-06-07 3 楼

To add more information about the topic:

you can't specifiy directly the definition on the capture side. Rather, this is the output of the capture session that defines the definition. e.g.

  • if you capture into a QtCaptureDecompressedVideoOutput, you shall specify the definition on this object.
故事和酒 2022-06-07 2 楼

The solution above (setPixelBufferAttributes:) does set the preview size correctly, but once movie recording starts, the preview image will get set back to it's original value (1280 x 1024 on my MBP) if you've set (almost) any compression options.

If that was just during movie recording that would be one thing, but once recording is complete, further calls to setPixelBufferAttributes will have no effect.

So, you can change the preview image size, as long as you don't plan on doing any actual compressed movie recording.

This is on 10.5.8/9L30, MBP with a GeForce 8600M. Any compression option except for no compression or QTCompressionOptionsSD240SizeH264Video breaks as described above.

rdar://7447812

感悟人生的甜 2022-06-07 1 楼

As described here, you can set the pixel buffer attributes within the output from your QTCaptureSession to change the resolution of the video being captured. For example:

[[[myCaptureSession outputs] objectAtIndex:0] setPixelBufferAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                                [NSNumber numberWithInt:480], kCVPixelBufferHeightKey,
                                                                [NSNumber numberWithInt:640], kCVPixelBufferWidthKey, nil]];

will set the video resolution to be 640x480 for the first output in your capture session. This should also adjust the camera settings themselves to have it return image frames of that size (if supported by the camera hardware).

You may also wish to use base MPEG4 encoding, instead of h.264, to do your realtime video recording. This can be set using code similar to the following:

NSArray *outputConnections = [mCaptureMovieFileOutput connections];
QTCaptureConnection *connection;
for (connection in outputConnections)
{
    if ([[connection mediaType] isEqualToString:QTMediaTypeVideo])
            [mCaptureMovieFileOutput setCompressionOptions:[QTCompressionOptions compressionOptionsWithIdentifier:@"QTCompressionOptionsSD480SizeMPEG4Video"] forConnection:connection];
}

h.264 encoding, particularly the Quicktime implementation, uses a lot more CPU power to encode than the base MPEG4.