Skip to content

Commit

Permalink
✨ 增加时长和缓存大小的显示
Browse files Browse the repository at this point in the history
  • Loading branch information
Littlefean committed Sep 19, 2024
1 parent ccdd17e commit fb7c71b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.venv/
# output
output/
*.mp4

assets/assets.py

Expand Down
17 changes: 13 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ def __init__(self):
self.init_ui()

self.output_dir = "output"
if not os.path.exists(self.output_dir):
os.mkdir(self.output_dir)

self.current_dir = ""

self.timer = QTimer(self) # 动态开启一个Qt定时器
Expand All @@ -36,6 +33,8 @@ def __init__(self):
self.capture_interval = 1000 # 默认间隔1000毫秒
self.frame_rate = 30 # 默认帧率
self.speed_rate = 20 # 默认速度倍率
self.cache_size = 0 # 缓存大小 MB
self.current_settings = "" # 当前设置 比如倍率和帧率的序列化信息

def init_ui(self):
self.setWindowTitle("延时录屏")
Expand Down Expand Up @@ -86,10 +85,18 @@ async def grab_screenshot(self, file_name="screenshot.png"):
t2 = perf_counter()
print(f"截图耗时:{t2 - t1:.2f}秒")

# 获取截图文件夹大小
size = os.path.getsize(file_name) / 1024 / 1024
print(f"截图大小:{size:.2f}MB")
self.cache_size += size

# 刷新提示
seconds = self.grab_index / self.frame_rate
self.tips_text.setText(
f"已保存第{self.grab_index + 1}帧,视频时长:{seconds:.2f}秒"
f"当前设定:{self.current_settings}\n"
f"已有帧数:{self.grab_index + 1}\n"
f"视频时长:{seconds:.2f}\n"
f"缓存大小:{self.cache_size:.2f}MB"
)
self.grab_index += 1

Expand Down Expand Up @@ -126,6 +133,8 @@ def start_screenshots(self):
self.current_dir = f"screenshots-{int(perf_counter())}"
dir_name = f"{self.output_dir}/{self.current_dir}"
os.mkdir(dir_name)
# 设置当前设置
self.current_settings = f"倍速{self.speed_rate},帧率{self.frame_rate}帧"

self.record_button.setText("停止录制")
self.timer.timeout.connect(
Expand Down

0 comments on commit fb7c71b

Please sign in to comment.