瀏覽代碼

!2 add function recording

pcacc 1 月之前
父節點
當前提交
c276928609
共有 5 個文件被更改,包括 103 次插入11 次删除
  1. 2 0
      app_dongri.py
  2. 1 1
      daily.json
  3. 3 10
      dongri_task.py
  4. 14 0
      scriptBase/comon.py
  5. 83 0
      scriptBase/record.py

+ 2 - 0
app_dongri.py

@@ -285,6 +285,7 @@ def add_auto_task(isMaxCollect, isJina, isSimple = False, isAddStrengh = False,
         if isSimple == False and is_within_n_minutes(get_todo_time("巨熊行动"), 20, 30):
             print("in fight bear")
             if len(task_queue) < 5:
+                start_recording()
                 task_queue.appendleft(task_returnAllLine())
                 task_queue.appendleft(task_useAnnimalSkill(True))
                 task_queue.appendleft(task_paticipateInTeam())
@@ -305,6 +306,7 @@ def add_auto_task(isMaxCollect, isJina, isSimple = False, isAddStrengh = False,
             always = True
             update_rungame_type(0)
             send_status(f'巨熊行动:在60min内,切换到无尽模式')
+        stop_recording()
         
         print("add special activity")
         # special activity

+ 1 - 1
daily.json

@@ -5,5 +5,5 @@
             "fight_bigMonster_times": 0
         }
     },
-    "runType": 0
+    "runType": 1
 }

+ 3 - 10
dongri_task.py

@@ -505,9 +505,6 @@ class task_fightMonster(dongri_task):
 
         if False == basic_operate.click_outside_search():
             return False
-
-        
-        
         
         if waitFindImg_withBool(monster_img.search, 2, 1):
             myTimeSleep_big()
@@ -1292,7 +1289,6 @@ class task_checkActivities(dongri_task):
             todo_list = result
             print(todo_list)
             print(get_todo_time("巨熊行动"))
-            
         return activityStr
 
 class task_visit_island(dongri_task):
@@ -1605,10 +1601,7 @@ class task_testFun(dongri_task):
     def __init__(self):
         super().__init__(f"测试功能")
     def run(self):
-        ret1, powerPos = pcacc_img.find_img_origin(special_activity_img.power_empty)
-        ret2, plusPos = pcacc_img.find_img_origin(special_activity_img.plus_small)
-        print(plusPos[0] - powerPos[0])
-        task_checkPower().run()
+        task_checkActivities().run()
         #task_paticipateInTeam().run()
         return True
 
@@ -1629,13 +1622,13 @@ if __name__ == '__main__':
     #task_fight_jina_only().run()
     #task_checkConfilits().run()
     #task_getStrength().run()
-    #task_checkActivities().run()
+    task_checkActivities().run()
     #task_checkMaster().run()
     #basic_operate.get_line_num()
     #yys_ocrAuto(check_img.line_orc)
     #basic_operate.go_town()
     #basic_operate.add_strength()
-    task_fightMonster(False, False,False).run()
+    #task_fightMonster(False, False,False).run()
     #task_checkHelp().run()
     #task_checkStoreRoom().run()
     #task_start_game(1)

+ 14 - 0
scriptBase/comon.py

@@ -11,6 +11,9 @@ from PIL import Image
 from PIL import ImageFilter
 import io
 from scriptBase.ocr import *
+from scriptBase.record import ScreenRecorder
+
+g_recorder = ScreenRecorder()
 
 def compress_image(image, target_size = 100 * 1024):
     # 调整图像尺寸,保持纵横比
@@ -297,6 +300,17 @@ def save_game_screen():
     screenshot.save(fileName)
     return True
 
+def start_recording():
+    global g_recorder
+    regionRet, regionPos = game_region()
+    print("record region,", regionPos)
+    g_recorder.start_recording(regionPos)
+
+def stop_recording():
+    global g_recorder
+    g_recorder.stop_recording()
+
+
 def yys_getRegion(region, isWidth= False):
     return getRegion('Mumu模拟器12', region, isWidth)
 

+ 83 - 0
scriptBase/record.py

@@ -0,0 +1,83 @@
+import time
+import cv2
+import numpy as np
+from PIL import ImageGrab
+import threading
+from datetime import datetime
+
+class ScreenRecorder:
+    def __init__(self, fps=15.0):
+        self.fps = fps
+        self.recording_thread = None
+        self.stop_event = threading.Event()  # 线程停止信号
+        self.writer = None
+
+    def record_with_timestamp(self, region=(0, 0, 1920, 1080)):
+        """多线程录屏方法"""
+        region = (region[0], region[1], region[2] + region[0], region[3] + region[1])
+        try:
+            curData = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
+            output = "temp_record/" + curData + ".mp4"
+            
+            # 计算实际帧尺寸并验证
+            width, height = region[2] - region[0], region[3] - region[1]
+            if width <= 0 or height <= 0:
+                raise ValueError("Invalid region dimensions")
+
+            fourcc = cv2.VideoWriter_fourcc(*'mp4v')
+            self.writer = cv2.VideoWriter(output, fourcc, float(self.fps), (width, height))
+            if not self.writer.isOpened():
+                raise RuntimeError("Failed to initialize VideoWriter")
+
+            while not self.stop_event.is_set():
+                img = ImageGrab.grab(bbox=region)
+                frame = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
+                
+                # 添加时间水印(带半透明背景)
+                overlay = frame.copy()
+                cv2.rectangle(overlay, (10, 10), (300, 60), (0, 0, 0), -1)
+                cv2.addWeighted(overlay, 0.5, frame, 0.5, 0, frame)
+                cv2.putText(frame, datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 
+                           (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
+                
+                self.writer.write(frame)
+                cv2.waitKey(int(1000 / self.fps))  # 控制帧率
+
+        except Exception as e:
+            print(f"Recording error: {str(e)}")
+        finally:
+            if self.writer:
+                self.writer.release()
+
+    def start_recording(self, region):
+        """启动录屏线程"""
+        if self.recording_thread and self.recording_thread.is_alive():
+            print("Recording is already running")
+            return
+        
+        self.stop_event.clear()
+        self.recording_thread = threading.Thread(
+            target=self.record_with_timestamp, 
+            args=(region,),
+            daemon=True  # 设为守护线程,主程序退出时自动终止
+        )
+        self.recording_thread.start()
+
+    def stop_recording(self):
+        """中止录屏"""
+        if self.recording_thread and self.recording_thread.is_alive():
+            self.stop_event.set()
+            self.recording_thread.join(timeout=2)  # 等待线程结束(超时2秒)
+            if self.writer:
+                self.writer.release()
+            print("Recording stopped")
+        else:
+            print("No active recording to stop")
+
+# 示例调用
+if __name__ == "__main__":
+    recorder = ScreenRecorder()
+    # 输入参数示例:left=100, top=100, width=800, height=600
+    recorder.start_recording(region=(884, 69, 608, 840))
+    time.sleep(15)
+    recorder.stop_recording()