usb camera recording and detour demo

This commit is contained in:
langolierz
2019-06-29 21:30:10 +00:00
parent c088e054fd
commit 03d9411edf
5 changed files with 49 additions and 22 deletions

View File

@@ -278,6 +278,15 @@ class Actions(object):
elif self.data.player_mode == 'next':
self.data.player_mode = 'now'
def toggle_detour_mode(self):
if self.data.settings['detour']['TRY_DEMO']['value'] == 'enabled':
if self.data.detour_active:
self.data.detour_active = False
self.video_driver.osc_client.send_message("/detour/end", True)
else:
self.data.detour_active = True
self.video_driver.osc_client.send_message("/detour/start", True)
def set_the_camera_colour_u_continuous(self, amount):
self.capture.set_colour(amount*255, None)

View File

@@ -41,6 +41,7 @@ class Data(object):
self.midi_port_index = 0
self.update_screen = True
self.player_mode = 'now'
self.detour_active = False
### persisted data (use default if doesnt exits):
self.bank_data = [self.create_empty_bank()]

View File

@@ -1 +1 @@
"1-0"
"1-1"

View File

@@ -64,10 +64,10 @@
"DEFAULT": ["load_slot_6_into_next_player","toggle_shaders"]
},
"q": {
"DEFAULT": ["load_slot_7_into_next_player", "increase_speed"]
"DEFAULT": ["load_slot_7_into_next_player", "toggle_detour_mode"]
},
"r": {
"DEFAULT": ["load_slot_8_into_next_player", "decrease_speed"]
"DEFAULT": ["load_slot_8_into_next_player"]
},
"s": {
"DEFAULT": ["load_slot_9_into_next_player","quit_the_program"]

View File

@@ -3,6 +3,7 @@ import subprocess
import datetime
import fractions
import picamera
import time
class OfCapture(object):
def __init__(self, root, osc_client, message_handler, data):
@@ -27,7 +28,7 @@ class OfCapture(object):
if not self.check_if_attached_with_picamera():
return
print('sending setup message !')
print('sending setup message !', self.capture_type)
self.osc_client.send_message("/capture/setup", self.capture_type)
self.has_capture = True
return True
@@ -124,25 +125,41 @@ class OfCapture(object):
def stop_recording(self):
#self.device.stop_recording()
self.osc_client.send_message("/capture/record/stop", True)
#set status to saving
mp4box_process, recording_name = self.convert_raw_recording()
self.is_recording = 'saving'
self.root.after(0, self.wait_for_recording_to_save, mp4box_process, recording_name)
self.wait_for_raw_file()
#set status to saving
self.update_capture_settings()
# return path to the video
def wait_for_raw_file(self):
if os.path.exists(self.video_dir + 'raw.h264'):
mp4box_process, recording_name = self.convert_raw_recording()
self.root.after(0, self.wait_for_recording_to_save, mp4box_process, recording_name)
self.update_capture_settings()
elif os.path.exists(self.video_dir + 'raw.mp4'):
recording_path , recording_name = self.generate_recording_path()
os.rename(self.video_dir + 'raw.mp4', recording_path )
self.is_recording = False
print('usb name is ', recording_name)
self.root.after(10000, self.data.create_new_slot_mapping_in_first_open, recording_name)
self.update_capture_settings()
else:
self.root.after(1000, self.wait_for_raw_file)
def convert_raw_recording(self):
recording_path , recording_name = self.generate_recording_path()
try:
mp4box_process = subprocess.Popen(['MP4Box', '-add', self.video_dir + '/raw.h264', recording_path])
return mp4box_process , recording_name
except Exception as e:
print(e)
if hasattr(e, 'message'):
error_info = e.message
else:
error_info = e
### wait for omx to finish creating video ...
if os.path.exists(self.video_dir + 'raw.h264'):
recording_path , recording_name = self.generate_recording_path()
try:
mp4box_process = subprocess.Popen(['MP4Box', '-add', self.video_dir + 'raw.h264', recording_path])
return mp4box_process , recording_name
except Exception as e:
print(e)
if hasattr(e, 'message'):
error_info = e.message
else:
error_info = e
self.message_handler.set_message('ERROR',error_info)
@@ -150,13 +167,13 @@ class OfCapture(object):
print('the poll is {}'.format(process.poll()))
if process.poll() is not None:
self.is_recording = False
os.remove(self.video_dir + '/raw.h264')
os.remove(self.video_dir + 'raw.h264')
self.data.create_new_slot_mapping_in_first_open(name)
else:
self.root.after(300, self.wait_for_recording_to_save, process, name)
def generate_recording_path(self):
rec_dir = self.video_dir + '/recordings'
rec_dir = self.video_dir + 'recordings'
if not os.path.exists(rec_dir):
os.makedirs(rec_dir)
date = datetime.datetime.now().strftime("%Y-%m-%d")