txlyre 7 сар өмнө
parent
commit
dca314c7f2
1 өөрчлөгдсөн 17 нэмэгдсэн , 8 устгасан
  1. 17 8
      main.py

+ 17 - 8
main.py

@@ -240,23 +240,32 @@ def sample(source, source_type, multiplier=1):
     return data
 
 
+def video2_extractor(q, data):
+    data = extract_lsbs(data)
+    data = whiten(data)
+
+    logger.info(f"Sample ready: {len(data)}b.")
+
+    q.put(data)
+
+
 def video2_sampler(q, source):
     with Device.from_id(abs(int(source))) as device:
         device.set_format(
-            1, device.info.frame_sizes[0].width, device.info.frame_sizes[0].height, pixel_format="YUYV"
+            1,
+            device.info.frame_sizes[0].width,
+            device.info.frame_sizes[0].height,
+            pixel_format="YUYV",
         )
 
         last = 0
         for frame in device:
             new = time.monotonic()
 
-            if new - last > 1.5:
-                data = extract_lsbs(bytes(frame))
-                data = whiten(data)
-
-                logger.info(f"Sample ready: {len(data)}b.")
-
-                q.put(data)
+            if new - last > 10:
+                threading.Thread(
+                    target=video2_extractor, args=(q, bytes(frame))
+                ).start()
 
                 last = new