访问任意 MacOS 应用程序的帧缓冲区
Access framebuffer for arbitrary MacOS application
我正在尝试为 Mac 上的任意应用程序捕获帧缓冲区并逐帧处理帧缓冲区。有没有办法利用应用程序内部帧缓冲区?我还注意到有一些 Graphics API 函数,例如 this 可以捕获整个屏幕,但我担心
A) 我需要弄清楚我的 window 在哪里并将其从整个屏幕图像中裁剪掉,这可能需要非零时间
B) 因为它捕获整个屏幕而不是一个 window,我想它会花费更长的时间。
我希望能够每秒捕捉和处理 20 帧,所以速度非常重要。
我有几个想法...
首先,也是最简单的,您可以启动 Quicktime(随 macOS 提供)并转到 File
->New screen recording
并录制一个屏幕的任意区域并将其保存在电影中,稍后分析帧。
其次,您可以使用 screencapture
(/usr/sbin/screencapture
) 并指定要捕获的矩形或 window id。手册页不正确且垃圾,所以使用以下内容查看实际选项:
screencapture -h
输出
usage: screencapture [-icMPmwsWxSCUtoa] [files]
-c force screen capture to go to the clipboard
-b capture Touch Bar - non-interactive modes only
-C capture the cursor as well as the screen. only in non-interactive modes
-d display errors to the user graphically
-i capture screen interactively, by selection or window
control key - causes screen shot to go to clipboard
space key - toggle between mouse selection and
window selection modes
escape key - cancels interactive screen shot
-m only capture the main monitor, undefined if -i is set
-M screen capture output will go to a new Mail message
-o in window capture mode, do not capture the shadow of the window
-P screen capture output will open in Preview
-I screen capture output will in a new Messages message
-s only allow mouse selection mode
-S in window capture mode, capture the screen not the window
-t<format> image format to create, default is png (other options include pdf, jpg, tiff and other formats)
-T<seconds> Take the picture after a delay of <seconds>, default is 5
-w only allow window selection mode
-W start interaction in window selection mode
-x do not play sounds
-a do not include windows attached to selected windows
-r do not add dpi meta data to image
-l<windowid> capture this windowsid
-R<x,y,w,h> capture screen rect
-B<bundleid> screen capture output will open in app with bundleidBS
files where to save the screen capture, 1 file per screen
如您所见,-l
、-R
选项非常有用。
我写了一个小程序来获取 windowids
.
的列表
window 的大小和文件格式对速度有影响。我发现 JPEG
通常最快,而 PNG
通常最慢。我可以每秒以合理的大小 window 获得 20 帧:
time for i in {0..99}; do screencapture -l 56 -t jpg fred-$i.jpg; done
我在另一个链接的答案中从 windowlist
程序中得到 56
。
我正在尝试为 Mac 上的任意应用程序捕获帧缓冲区并逐帧处理帧缓冲区。有没有办法利用应用程序内部帧缓冲区?我还注意到有一些 Graphics API 函数,例如 this 可以捕获整个屏幕,但我担心
A) 我需要弄清楚我的 window 在哪里并将其从整个屏幕图像中裁剪掉,这可能需要非零时间
B) 因为它捕获整个屏幕而不是一个 window,我想它会花费更长的时间。
我希望能够每秒捕捉和处理 20 帧,所以速度非常重要。
我有几个想法...
首先,也是最简单的,您可以启动 Quicktime(随 macOS 提供)并转到 File
->New screen recording
并录制一个屏幕的任意区域并将其保存在电影中,稍后分析帧。
其次,您可以使用 screencapture
(/usr/sbin/screencapture
) 并指定要捕获的矩形或 window id。手册页不正确且垃圾,所以使用以下内容查看实际选项:
screencapture -h
输出
usage: screencapture [-icMPmwsWxSCUtoa] [files]
-c force screen capture to go to the clipboard
-b capture Touch Bar - non-interactive modes only
-C capture the cursor as well as the screen. only in non-interactive modes
-d display errors to the user graphically
-i capture screen interactively, by selection or window
control key - causes screen shot to go to clipboard
space key - toggle between mouse selection and
window selection modes
escape key - cancels interactive screen shot
-m only capture the main monitor, undefined if -i is set
-M screen capture output will go to a new Mail message
-o in window capture mode, do not capture the shadow of the window
-P screen capture output will open in Preview
-I screen capture output will in a new Messages message
-s only allow mouse selection mode
-S in window capture mode, capture the screen not the window
-t<format> image format to create, default is png (other options include pdf, jpg, tiff and other formats)
-T<seconds> Take the picture after a delay of <seconds>, default is 5
-w only allow window selection mode
-W start interaction in window selection mode
-x do not play sounds
-a do not include windows attached to selected windows
-r do not add dpi meta data to image
-l<windowid> capture this windowsid
-R<x,y,w,h> capture screen rect
-B<bundleid> screen capture output will open in app with bundleidBS
files where to save the screen capture, 1 file per screen
如您所见,-l
、-R
选项非常有用。
我写了一个小程序来获取 windowids
window 的大小和文件格式对速度有影响。我发现 JPEG
通常最快,而 PNG
通常最慢。我可以每秒以合理的大小 window 获得 20 帧:
time for i in {0..99}; do screencapture -l 56 -t jpg fred-$i.jpg; done
我在另一个链接的答案中从 windowlist
程序中得到 56
。