作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 mac 应用程序中,我需要抓取屏幕并将其发送到另一端,
有可能通过 AVCaptureSession ?
如果是,我只需要 RGB 或 YUV 数据而不是音频,是否可以配置它?
如果不是 AVFoundation 类/框架,那么推荐哪个?
最佳答案
如果你想要一个连续的 yuv 图像流,你可以这样做:
#import <AVFoundation/AVFoundation.h>
@interface ScreenCapture() <AVCaptureVideoDataOutputSampleBufferDelegate>
@property (nonatomic) AVCaptureSession *captureSession;
@end
@implementation ScreenCapture
- (instancetype)init
{
self = [super init];
if (self) {
self.captureSession = [[AVCaptureSession alloc] init];
AVCaptureScreenInput *input = [[AVCaptureScreenInput alloc] initWithDisplayID:CGMainDisplayID()];
[self.captureSession addInput:input];
AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[self.captureSession addOutput:output];
// TODO: create a dedicated queue.
[output setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
[self.captureSession startRunning];
}
return self;
}
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
// sampleBuffer contains screen cap, for me it's yuv
}
@end
这给了我大约 15fps。您可以通过降低最低帧率来获得更高的帧率:
input.minFrameDuration = CMTimeMake(1, 60);
对于更成熟的实现,更多的错误检查,请参阅 Apple 的 AVScreenShack sample code .
关于c++ - 使用 AVScreenCaptureInput 进行 OSX 屏幕捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34442579/
在我的 mac 应用程序中,我需要抓取屏幕并将其发送到另一端, 有可能通过 AVCaptureSession ? 如果是,我只需要 RGB 或 YUV 数据而不是音频,是否可以配置它? 如果不是 AV
我是一名优秀的程序员,十分优秀!