import sys import os import pyzed.sl as sl import threading import time from signal import signal, SIGINT zed_list = [] timestamp_list = [] thread_list = [] stop_signal = False frame_list = [] record_time_per_svo = 1800 name_time_list = [] root_path = "/data/" filenames = os.listdir(root_path) for f in filenames: w_time = os.path.getctime(root_path + f) name_time_list.append((f, w_time)) sorted_list = sorted(name_time_list, key=lambda x: x[1], reverse=True) recent_file = sorted_list[0] target_dir = str(root_path) + str(recent_file[0]) def handler(signal, frame): global stop_signal global zed_list global target_dir stop_signal = True filepath = '%s/log.txt'%(target_dir) f = open(filepath, 'w') f.write('record succesfully stopped') f.close() time.sleep(2) exit() def grab_run(index, cameras): global stop_signal global zed_list global timestamp_list global left_list global depth_list global frame_list global taget_dir runtime = sl.RuntimeParameters() shard_count = 0 while not stop_signal: #I need loop and 1800ms if frame_list[index] % record_time_per_svo == 0: filepath = '%s/%s_%s.svo'%(target_dir,str(shard_count).zfill(3),cameras[index].id+1) record_params = sl.RecordingParameters(filepath, sl.SVO_COMPRESSION_MODE.H264) err = zed_list[index].enable_recording(record_params) #print('new shard created') shard_count += 1 if zed_list[index].grab(runtime) == sl.ERROR_CODE.SUCCESS : frame_list[index] += 1 #if zed_list[index].grab() == "SUCCESS": # zed_list[index].record() #print("Frame count: " + str(frame_list[index]), end='\r') if zed_list[index].grab(runtime) == sl.ERROR_CODE.SUCCESS : frame_list[index] += 1 zed_list[index].disable_recording() #print('saved') def main(): signal(SIGINT, handler) #print('Running...') init = sl.InitParameters() init.camera_resolution = sl.RESOLUTION.HD1080 init.camera_fps = 30 name_list = [] cameras = sl.Camera.get_device_list() #print(cameras) index = 0 for cam in cameras: init.set_from_serial_number(cam.serial_number) name_list.append("ZED {}".format(cam.serial_number)) print("Opening {}".format(name_list[index])) zed_list.append(sl.Camera()) timestamp_list.append(0) frame_list.append(0) status = zed_list[index].open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status)) zed_list[index].close() index = index +1 #Start camera threads for index in range(0, len(zed_list)): if zed_list[index].is_opened(): thread_list.append(threading.Thread(target=grab_run, args=(index,cameras))) thread_list[index].start() if __name__ == "__main__": main()