记一次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')
相关推荐
kishu_iOS&AI2 小时前
机器学习 —— 线性回归(实例)
人工智能·python·机器学习·线性回归
架构师老Y2 小时前
007、微服务架构设计与服务拆分策略
python·微服务·架构
skilllite作者2 小时前
SkillLite 多入口架构实战:CLI / Python SDK / MCP / Desktop / Swarm 一页理清
开发语言·人工智能·python·安全·架构·rust·agentskills
ZC跨境爬虫2 小时前
批量爬取小说章节并优化排版(附完整可运行脚本)
前端·爬虫·python·自动化
ths5122 小时前
Python 正则表达式实战指南:从入门到精通(12 个高频案例)(三)
python·正则表达式
ZC跨境爬虫2 小时前
海南大学交友平台登录页开发实战day4(解决python传输并读取登录信息的问题)
开发语言·前端·python·flask·html
Wyawsl2 小时前
Python操作MySQL数据库
数据库·python·mysql
SuperEugene3 小时前
Python 异步 async/await:为什么 AI 框架大量使用?| 基础篇
开发语言·人工智能·python
SMF19193 小时前
【uv】Python包管理器uv安装和应用
开发语言·python·uv
gergul3 小时前
在llama-cpp-python中使用自己编译的llama.cpp,解决pip install llama-cpp-python报错
python·llama·llama.cpp·llamacpppython