-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
record.py
62 lines (51 loc) · 1.82 KB
/
record.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from klipper.gcode import *
from pattern_info import PatternInfo
import numpy as np
import subprocess
import time
from pathlib import Path
from constants import *
ffmpeg_cmd = [
"ffmpeg",
"-y",
"-f",
"v4l2",
"-framerate",
FRAMERATE,
"-video_size",
VIDEO_RESOLUTION,
"-input_format",
"mjpeg",
"-i",
VIDEO_DEVICE,
]
# TODO: make this return a list of files that are saved
# TODO: make this save to a unique folder each run (maybe this should be passed in?)
def record_pattern(info: PatternInfo, buffer_distance: float, output_directory: str) -> list:
send_gcode("STATUS_OFF") # Turn off LEDs
send_gcode("LASER_ON") # Turn on line laser
send_gcode("SET_LED LED=chamber_lights WHITE=0")
time.sleep(0.5)
lines_start_y = info.lines_start_y()
y_values = np.asarray(lines_start_y) + CAMERA_OFFSET_Y
scan_start_x = info.start_x + buffer_distance + CAMERA_OFFSET_X
scan_length = info.line_length - buffer_distance * 2
scan_end_x = scan_start_x + scan_length
video_files = []
Path(output_directory).mkdir(parents=True, exist_ok=True)
for index, y_value in enumerate(y_values):
move_absolute(scan_start_x, y_value, LASER_FOCUS_HEIGHT, 30000)
wait_until_printer_at_location(scan_start_x, y_value)
# start recording
video_file = f"{output_directory}/line{index}.mp4"
video_files.append(video_file)
with subprocess.Popen(ffmpeg_cmd + [video_file]) as ffmpeg:
time.sleep(FFMPEG_START_DELAY)
print(move_absolute(scan_end_x, f=400))
wait_until_printer_at_location(scan_end_x)
# stop recording
ffmpeg.terminate()
time.sleep(FFMPEG_STOP_DELAY)
send_gcode("LASER_OFF")
send_gcode("SET_LED LED=chamber_lights WHITE=1")
return video_files