记一次renderdoc自动截帧

官方文档,官方文档写的真是一言难尽,看过的都懂

1、python 环境搭建:

github上下载renderdoc截帧工具,

然后使用Visual Studio打开源码根目录下的renderdoc.sln文件

打开后直接点击【生成解决方案】

编译好后会在源码根目录生成一个x64\Development目录, 目录结构如下图

pymodules就是关键目录了

2、windows截帧

1)使用renderdoc打开被测试应用

此次的方案需要在已打开被测试应用的基础上进行

2)python中添加如下代码即可

python 复制代码
import shutil
import sys
import os
import time

renderdoc = r'D:\pythonScripts\TestRenderDocTools\renderdoc'
os.environ["PATH"] += os.pathsep + os.path.abspath(renderdoc)
if sys.platform == 'win32' and sys.version_info[1] >= 8:
    os.add_dll_directory(renderdoc)

renderdoc_py = r"D:\pythonScripts\TestRenderDocTools\renderdoc\pymodules"
sys.path.append(renderdoc_py)
import renderdoc as rd


# 触发一次windows截帧并将截图保存至指定目录
def capture(savedPath):
    # 获取远程设备目标
    target_code = rd.EnumerateRemoteTargets("", 0)

    # # 创建目标控制连接
    targetControl = rd.CreateTargetControl(r"localhost", target_code, "capture_windows", True)
    if not targetControl:
        return False, '创建目标控制失败'
    # 进行一次截帧
    result = targetControl.TriggerCapture(1)

    # 等待截帧完成并将对应的数据放到指定目录
    startTime, isSuccess = time.time(), False
    while time.time()-startTime < 20:
        message = targetControl.ReceiveMessage(None)
        cap_path, cap_id, frame_num, api = message.newCapture.path, message.newCapture.captureId, message.newCapture.frameNumber, message.newCapture.api
        if cap_path:
            print(f'cap_path = {cap_path}, cap_id={cap_id}, frame_num={frame_num}, api={api}')
            # 将文件cppy到指定目录
            # 如果指定目录不存在则创建
            if not os.path.isdir(savedPath):
                os.makedirs(savedPath, exist_ok=True)

            # 将文件移动到指定目录
            shutil.move(cap_path, savedPath)

            isSuccess = True
            break

        time.sleep(1)

    if isSuccess:
        return True, '截帧成功'
    else:
        return False, '截帧超时失败'

capture(r'D:\RenderDoc\test')
相关推荐
AI街潜水的八角21 小时前
Python电脑屏幕&摄像头录制软件(提供源代码)
开发语言·python
hadage23321 小时前
--- git 的一些使用 ---
开发语言·git·python
笨笨聊运维1 天前
CentOS官方不维护版本,配置python升级方法,无损版
linux·python·centos
Gerardisite1 天前
如何在微信个人号开发中有效管理API接口?
java·开发语言·python·微信·php
小毛驴8501 天前
软件设计模式-装饰器模式
python·设计模式·装饰器模式
闲人编程1 天前
Python的导入系统:模块查找、加载和缓存机制
java·python·缓存·加载器·codecapsule·查找器
weixin_457760001 天前
Python 数据结构
数据结构·windows·python