使用AVScreenCaptureInput的OSX屏幕捕获
OSX Screencapturing using AVScreenCaptureInput
在我的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
这给了我大约每秒15帧的速度。您可以通过降低最低帧速率来获得更高的帧速率:
input.minFrameDuration = CMTimeMake(1, 60);
有关更成熟的实现,即更多的错误检查,请参阅Apple的AVScreenShack示例代码。
相关文章:
- UE4-如何在给定4个屏幕坐标的情况下缩放纹理或材质
- OSX MetalKit CVMetalTextureCacheCreateTextureFromImage失败,状态:
- 如何在GTK程序运行时禁用屏幕保护程序/电源管理/屏幕消隐
- 使用 SFML 和 C++ 将 Pixel 打印到屏幕上
- 在 Windows 8/10 技术中完全实时的屏幕捕获,没有延迟
- OSX蓝牙打开RFCOMMChannelAsync声称已连接,但未建立连接,并且从未调用过委托
- Winapi:屏幕截图未显示在窗口中
- 在OSX上使用CMake将Adobe的XMP工具包构建为共享库的最简单方法是什么?
- 如何在快板的屏幕中显示子位图的绘制?
- C ++是否有C ++ 17 OSX 10.13.6的标志
- 按回车键后输出屏幕关闭
- 要在屏幕上绘制一些小瓷砖,我应该使用 QQuickItem 还是 QQuickPaintedItem?
- SFML 向下移动时如何围绕屏幕中心旋转?
- 截取屏幕截图后程序卡住
- 各种版本的 Mac OSX 向后兼容性如何?(Xcode C++
- OSX clang++:用于 cpp 文件中显式实例化模板的体系结构x86_64的未定义符号
- 在OSX中使用CGDisplayStream存储屏幕记录的特定文件路径
- OSX+屏幕外渲染+CoreGL+帧缓冲区+着色器=头疼
- 使用AVScreenCaptureInput的OSX屏幕捕获
- OSX以最小的延迟将像素推到屏幕上