-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture_handler.py
More file actions
37 lines (31 loc) · 1.09 KB
/
Copy pathcapture_handler.py
File metadata and controls
37 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import subprocess
import asyncio
from config import *
class CaptureHandler:
async def start(self):
ffmpeg_argv = [
"ffmpeg",
"-fflags",
"+genpts",
"-init_hw_device",
"d3d11va",
"-threads:v",
"1",
"-filter_complex",
f"ddagrab=0:output_fmt=87:draw_mouse=0:framerate={capture_rate}:video_size={capture_width}x{capture_height}:offset_x={int(monitor_width / 2 - capture_width / 2)}:offset_y={int(monitor_height / 2 - capture_height / 2)},hwdownload,format=bgra",
"-f",
"rawvideo",
"-",
]
self.ffmpeg_process = await asyncio.subprocess.create_subprocess_exec(
*ffmpeg_argv,
stdout=subprocess.PIPE,
limit=capture_width * capture_height * 4 * 2,
)
async def read(self):
buf = b""
while len(buf) < capture_width * capture_height * 4:
buf += await self.ffmpeg_process.stdout.read(
capture_width * capture_height * 4 - len(buf)
)
return buf