如何在Python中使用Libvirt录制VM屏幕?

发布于 2025-01-22 20:15:38 字数 386 浏览 5 评论 0原文

我正在使用Python进行Testautomation,在那里我正在与KVM服务器上的各种主机一起工作。为了实现这一目标,我正在使用libvirt和Python3。现在,我想记录测试以查看以后发生的事情。

我尝试了类似的事情

import libvirt
conn = libvirt.open("...")
vm = conn.lookupByName('win10')
stream = conn.newStream()
while True:
    img = vm.screenshot(stream, 0)
    ....

,但这只会呈现约9张图像,因此非常懒惰。有没有办法更快 /更快地完成此操作?

虚拟机设置为使用Spice Display服务器。

I'm doing testautomation with python where I'm working with various hosts on a kvm server. To achieve this, I'm using libvirt and python3. Now I want to record the tests to see whats going on afterwards.

I tried something like

import libvirt
conn = libvirt.open("...")
vm = conn.lookupByName('win10')
stream = conn.newStream()
while True:
    img = vm.screenshot(stream, 0)
    ....

but this only renders about 9 images per second, thus its very laggy. Is there a way get this done faster / more performant?

The virtual machines are set to use the spice display server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(1

樱&纷飞 2025-01-29 20:15:38

假设VM配置了VNC服务器,则打开与VNC的连接并以这种方式接收屏幕更新会更有效,从服务器推开。如果已经存在某个地方可以连接到VNC并记录到视频流的地方,我不会感到惊讶。如果不是,则“ GTK-VNC”库通过Python导出其API,可用于构建此类工具。

Assuming the VM has a VNC server configured, it would be far more effective to open a connection to VNC and receive the screen updates on the fly that way, pushed from the server. I wouldn't be surprised if there's already python code that exists somewhere to connect to VNC and record to a video stream. If not, the 'gtk-vnc' library exports its API via python and could be used to build such a tool.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文