我需要将我的应用程序放在全屏视频上并捕获它以放入我的 python tkinter 应用程序中的“画中画”框架中。我回顾了通常的嫌疑人(图像抓取, mss等),但它们似乎都只是抓取监视器上可见的内容。似乎没有人能够抓住一扇看不见的窗户。
我在以下位置找到了这个 C 程序堆栈溢出看起来很有希望:
- 使用 X11 的 Xcomposite 扩展获取被覆盖、不可见或最小化的窗口的屏幕截图 https://stackoverflow.com/questions/21512177/get-a-screenshot-of-a-window-that-is-cover-or-not-visible-or-minimized-with-xcom
#include <stdlib.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/X.h>
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xrender.h>
int
main ()
{
Display *display = XOpenDisplay (NULL);
XID xid = 90177543; // xdotool search --name "World of Warcraft" | head -1
// Check if Composite extension is enabled
int event_base_return;
int error_base_return;
if (XCompositeQueryExtension (display, &event_base_return, &error_base_return))
printf ("COMPOSITE IS ENABLED!\n");
// Requests the X server to direct the hierarchy starting at window to off-screen storage
XCompositeRedirectWindow (display, xid, CompositeRedirectAutomatic);
// Preventing the backing pixmap from being freed when the window is hidden/destroyed
// If you want the window contents to still be available after the window has been destroyed,
// or after the window has been resized (but not yet redrawn), you can increment the backing
// pixmaps ref count to prevent it from being deallocated.
Pixmap pixmap = XCompositeNameWindowPixmap (display, xid);
// Get window attributes
XWindowAttributes attr;
Status s = XGetWindowAttributes (display, xid, &attr);
if (s == 0)
printf ("Fail to get window attributes!\n");
// Extract the data
XRenderPictFormat *format = XRenderFindVisualFormat (display, attr.visual);
int width = attr.width;
int height = attr.height;
int depth = attr.depth;
// What we need to do now is to create an XRender Picture for the window,
// which we'll need to draw it with the Render extension.
// A picture is a basically a handle to a server side struct with some
// additional information about a drawable (in this case a window),
// such as its format, which clipping region should be used when
// drawing it (if any), whether it should be tiled etc.
XRenderPictureAttributes pa;
pa.subwindow_mode = IncludeInferiors;
Picture picture = XRenderCreatePicture (display, xid, format, CPSubwindowMode, &pa);
// We now have all the information we need in order to be able to draw the window
// using the Xrender extension, and we've created and prepared a source picture
// for the window for this purpose.
// The Xrender function we'll use to draw the window is XRenderComposite().
//XRenderComposite (display, PictOpSrc, picture, None, ???destination???, 0,0, 0,0, 0,0, width, height);
XFreePixmap (display, pixmap);
XCompositeUnredirectWindow (display, xid, CompositeRedirectAutomatic);
return 0;
}
现在真正的问题...
我的问题是这一部分:
#include <X11/Xlib.h>
#include <X11/X.h>
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xrender.h>
所有这些文件都位于/usr/include/X11
除了<X11/extensions/Xcomposite.h>
。我可以在哪里找到它?
Ubuntu 16.04 LTS (ESM),内核 4.14.216-0414216-通用。太忙于学习新东西而无法打破,嗯,错误,升级到新版本。
FWIW这是一个已经可以使用的音乐播放器应用程序,单击按钮即可调低电视音量并恢复音乐。我只是增强它以移动到电视上,拍摄全屏视频并将其放入专辑插图通常旋转的 tkinter 框架中。定时器结束后,电视恢复,音乐播放器移回其来源的其他显示器。因此,我认为我找到的这个 C 程序是唯一的解决方案,但我欢迎罐装解决方案。