简体   繁体   中英

How do I programmatically video record a window / GUI application in python?

I would like to video record a GUI application (specifically RViz) programmatically since I am running an experiment multiple times and would like to automate and synchronize those recordings with the run. RViz itself offers no recording service and recommends SimpleScreenRecorder. Are there any libraries that offer this functionality?

System: Linux (Ubuntu)

Preferred language: python

I didn't find any suitable tools so I wrote up my own that should work on all Linux systems: https://github.com/LemonPi/window_recorder

You use it as a context manager, supplying either no window names to prompt you to click a window, or a list of window names to attempt to capture (the first one that's valid gets matched). For example,

from window_recorder.recorder import WindowRecorder
import time

# passing in nothing as the window name will allow you to select the window by clicking
# want to capture an RViz window, which could have name "RViz*" as well
with WindowRecorder(["RViz*", "RViz"], frame_rate=30.0, name_suffix="rviz"):
    # do things...
    time.sleep(0.1)
    start = time.time()
    while time.time() - start < 2:
        time.sleep(0.1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM