SunFounder PiCrawler Kit
Recording can be stopped or started by pressing the keys on the keyboard.
• Press q to begin recording or pause/continue, e to stop recording or save.
• If you want to exit the program, press esc.
Code
from time import sleep,strftime,localtime
from vilib import Vilib
import readchar
manual = '''
Press keys on keyboard to control recording:
Q: record/pause/continue
E: stop
ESC: Quit
'''
def print_overwrite(msg, end='', flush=True):
print('\r\033[2K', end='',flush=True)
print(msg, end=end, flush=True)
def main():
rec_flag = 'stop' # start,pause,stop
vname = None
Vilib.rec_video_set["path"] = "/home/pi/Videos/" # set path
Vilib.camera_start(vflip=False,hflip=False)
Vilib.display(local=True,web=True)
sleep(0.8) # wait for startup
print(manual)
while True:
# read keyboard
key = readchar.readkey()
key = key.lower()
# start,pause
if key == 'q':
key = None
if rec_flag == 'stop':
rec_flag = 'start'
# set name
vname = strftime("%Y-%m-%d-%H.%M.%S", localtime())
Vilib.rec_video_set["name"] = vname
# start record
Vilib.rec_video_run()
Vilib.rec_video_start()
print_overwrite('rec start ...')
elif rec_flag == 'start':
rec_flag = 'pause'
Vilib.rec_video_pause()
print_overwrite('pause')
(continues on next page)
3.8. Record Video 63