You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Windows 10游戏录制完成时自动生成侧载文件并填充数据

实现Windows Game Bar录制完成后自动生成侧载文件

方法1:Python文件监听脚本(推荐)

利用watchdog库监听Game Bar录制文件的保存目录,当检测到新的.mp4录制文件生成时,自动创建对应命名的侧载文件并填充默认标签。

操作步骤:

  1. 安装依赖库:
pip install watchdog
  1. 编写监听脚本:
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import os

# 替换为你的Game Bar录制保存目录
CAPTURES_DIR = r"C:\Users\你的用户名\Videos\Captures"
# 自定义默认标签,每行一个
DEFAULT_TAGS = [
    "游戏录制",
    "Windows Game Bar",
    "自动生成标签"
]

class CaptureHandler(FileSystemEventHandler):
    def on_created(self, event):
        # 仅处理文件,忽略目录
        if not event.is_directory:
            file_path = event.src_path
            # 只针对.mp4录制文件
            if file_path.endswith(".mp4"):
                # 生成txt格式侧载文件路径
                sidecar_path = f"{file_path}.txt"
                
                # 若需生成JSON格式,替换为以下代码块:
                # import json
                # tag_data = {"tags": DEFAULT_TAGS}
                # with open(sidecar_path.replace(".txt", ".json"), "w", encoding="utf-8") as f:
                #     json.dump(tag_data, f, ensure_ascii=False, indent=2)
                
                # 写入txt格式标签
                with open(sidecar_path, "w", encoding="utf-8") as f:
                    f.write("\n".join(DEFAULT_TAGS))
                print(f"已生成侧载文件:{sidecar_path}")

if __name__ == "__main__":
    event_handler = CaptureHandler()
    observer = Observer()
    observer.schedule(event_handler, CAPTURES_DIR, recursive=False)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()
  1. 运行与自启:
    将脚本保存为game_bar_watcher.py,运行后保持后台即可。若要开机自启,将脚本快捷方式放入C:\Users\<你的用户名>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup目录。

方法2:PowerShell文件监听脚本

无需额外安装软件,用原生PowerShell实现文件监听:

$capturesDir = "C:\Users\你的用户名\Videos\Captures"
$defaultTags = @("游戏录制", "Windows Game Bar", "自动生成标签")

# 初始化文件监听器
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $capturesDir
$watcher.Filter = "*.mp4"
$watcher.IncludeSubdirectories = $false
$watcher.EnableRaisingEvents = $true

# 定义文件创建事件处理逻辑
$action = {
    $filePath = $Event.SourceEventArgs.FullPath
    $sidecarPath = "$filePath.txt"
    # 写入默认标签
    $defaultTags | Out-File -FilePath $sidecarPath -Encoding utf8
    Write-Host "已生成侧载文件:$sidecarPath"
}

# 绑定事件
Register-ObjectEvent $watcher "Created" -Action $action

# 保持脚本运行
Write-Host "监听已启动,按Ctrl+C停止..."
while ($true) { Start-Sleep 1 }

将脚本保存为game_bar_watcher.ps1,右键用PowerShell运行。若要开机自启,创建批处理文件start_watcher.bat:

@echo off
powershell -WindowStyle Hidden -ExecutionPolicy Bypass -File "C:\你的脚本路径\game_bar_watcher.ps1"

再将批处理快捷方式放入Startup目录即可。

注意事项

  • 务必替换脚本中的你的用户名为实际Windows用户名,或直接填写完整的Captures目录路径(可在Game Bar设置→捕获中查看/修改保存位置)。
  • 自定义标签只需修改脚本中的DEFAULT_TAGS列表内容即可。

内容的提问来源于stack exchange,提问作者iguors

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 21:25:17