mirror of
https://github.com/tcsenpai/pensieve.git
synced 2025-06-06 19:25:24 +00:00
feat(screen-recorder): save webp for win
This commit is contained in:
parent
7f8c846e51
commit
ea3cd2e66e
@ -4,7 +4,7 @@ import os
|
|||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
import imagehash
|
import imagehash
|
||||||
from PIL import ImageGrab
|
from PIL import ImageGrab, Image
|
||||||
import win32gui
|
import win32gui
|
||||||
import win32process
|
import win32process
|
||||||
import psutil
|
import psutil
|
||||||
@ -49,9 +49,10 @@ def take_screenshot(base_dir, previous_hashes, threshold, screen_sequences, date
|
|||||||
safe_monitor_name = ''.join(c for c in monitor.name if c.isalnum() or c in ('_', '-'))
|
safe_monitor_name = ''.join(c for c in monitor.name if c.isalnum() or c in ('_', '-'))
|
||||||
logging.info(f"Processing monitor: {safe_monitor_name}")
|
logging.info(f"Processing monitor: {safe_monitor_name}")
|
||||||
|
|
||||||
jpeg_filename = os.path.join(base_dir, date, f"screenshot-{timestamp}-of-{safe_monitor_name}.jpg")
|
webp_filename = os.path.join(base_dir, date, f"screenshot-{timestamp}-of-{safe_monitor_name}.webp")
|
||||||
|
|
||||||
img = ImageGrab.grab(bbox=(monitor.x, monitor.y, monitor.x + monitor.width, monitor.y + monitor.height))
|
img = ImageGrab.grab(bbox=(monitor.x, monitor.y, monitor.x + monitor.width, monitor.y + monitor.height))
|
||||||
|
img = img.convert("RGB")
|
||||||
current_hash = imagehash.phash(img)
|
current_hash = imagehash.phash(img)
|
||||||
|
|
||||||
if safe_monitor_name in previous_hashes and current_hash - previous_hashes[safe_monitor_name] < threshold:
|
if safe_monitor_name in previous_hashes and current_hash - previous_hashes[safe_monitor_name] < threshold:
|
||||||
@ -70,11 +71,11 @@ def take_screenshot(base_dir, previous_hashes, threshold, screen_sequences, date
|
|||||||
"sequence": screen_sequences[safe_monitor_name],
|
"sequence": screen_sequences[safe_monitor_name],
|
||||||
}
|
}
|
||||||
|
|
||||||
img.save(jpeg_filename, format="JPEG", quality=85)
|
img.save(webp_filename, format="WebP", quality=85)
|
||||||
write_image_metadata(jpeg_filename, metadata)
|
write_image_metadata(webp_filename, metadata)
|
||||||
save_screen_sequences(base_dir, screen_sequences, date)
|
save_screen_sequences(base_dir, screen_sequences, date)
|
||||||
|
|
||||||
screenshots.append(jpeg_filename)
|
screenshots.append(webp_filename)
|
||||||
worklog.write(f"{timestamp} - {safe_monitor_name} - Saved\n")
|
worklog.write(f"{timestamp} - {safe_monitor_name} - Saved\n")
|
||||||
|
|
||||||
return screenshots
|
return screenshots
|
||||||
|
Loading…
x
Reference in New Issue
Block a user