Lint fixes
This commit is contained in:
parent
7fd5f5c4f8
commit
284ec129d9
1 changed files with 35 additions and 32 deletions
|
@ -292,7 +292,8 @@ class CameraPiPlugin(CameraPlugin):
|
||||||
|
|
||||||
multifile = not video_file
|
multifile = not video_file
|
||||||
if multifile and not (directory and split_duration):
|
if multifile and not (directory and split_duration):
|
||||||
return None, 'No video_file specified for single file capture and no directory/split_duration specified for multifile split'
|
return None, 'No video_file specified for single file capture and no directory/split_duration ' + \
|
||||||
|
'specified for multi-file split'
|
||||||
|
|
||||||
camera = self._get_camera(**opts)
|
camera = self._get_camera(**opts)
|
||||||
video_file = os.path.abspath(os.path.expanduser(video_file))
|
video_file = os.path.abspath(os.path.expanduser(video_file))
|
||||||
|
@ -306,39 +307,41 @@ class CameraPiPlugin(CameraPlugin):
|
||||||
self._recording_stop_condition.wait(timeout=duration)
|
self._recording_stop_condition.wait(timeout=duration)
|
||||||
self._recording_stop_condition.release()
|
self._recording_stop_condition.release()
|
||||||
self.logger.info('Video recorded to {}'.format(video_file))
|
self.logger.info('Video recorded to {}'.format(video_file))
|
||||||
else:
|
return
|
||||||
self.logger.info('Starting recording video files to directory {}'.format(directory))
|
|
||||||
|
|
||||||
i = 1
|
self.logger.info('Starting recording video files to directory {}'.format(directory))
|
||||||
start_time = time.time()
|
i = 1
|
||||||
end_time = None
|
end_time = None
|
||||||
if duration is not None:
|
timeout = split_duration
|
||||||
end_time = time.time() + duration
|
|
||||||
|
|
||||||
camera.start_recording(name_format % i, format='h264')
|
if duration is not None:
|
||||||
|
end_time = time.time() + duration
|
||||||
|
timeout = min(split_duration, duration)
|
||||||
|
|
||||||
|
camera.start_recording(name_format % i, format='h264')
|
||||||
|
self._recording_stop_condition.acquire()
|
||||||
|
self._recording_stop_condition.wait(timeout=timeout)
|
||||||
|
self._recording_stop_condition.release()
|
||||||
|
self.logger.info('Video file {} saved'.format(name_format % i))
|
||||||
|
|
||||||
|
while True:
|
||||||
|
i += 1
|
||||||
|
timeout = None
|
||||||
|
|
||||||
|
if end_time:
|
||||||
|
remaining_duration = end_time - time.time()
|
||||||
|
timeout = min(split_duration, remaining_duration)
|
||||||
|
if remaining_duration <= 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
camera.split_recording(name_format % i)
|
||||||
self._recording_stop_condition.acquire()
|
self._recording_stop_condition.acquire()
|
||||||
self._recording_stop_condition.wait(timeout=split_duration)
|
should_stop = self._recording_stop_condition.wait(timeout=timeout)
|
||||||
self._recording_stop_condition.release()
|
self._recording_stop_condition.release()
|
||||||
self.logger.info('Video file {} saved'.format(name_format % i))
|
self.logger.info('Video file {} saved'.format(name_format % i))
|
||||||
|
|
||||||
while True:
|
if should_stop:
|
||||||
i += 1
|
break
|
||||||
remaining_duration = None
|
|
||||||
|
|
||||||
if end_time:
|
|
||||||
remaining_duration = end_time - time.time()
|
|
||||||
split_duration = min(split_duration, remaining_duration)
|
|
||||||
if remaining_duration <= 0:
|
|
||||||
break
|
|
||||||
|
|
||||||
camera.split_recording(name_format % i)
|
|
||||||
self._recording_stop_condition.acquire()
|
|
||||||
should_stop = self._recording_stop_condition.wait(timeout=split_duration)
|
|
||||||
self._recording_stop_condition.release()
|
|
||||||
self.logger.info('Video file {} saved'.format(name_format % i))
|
|
||||||
|
|
||||||
if should_stop:
|
|
||||||
break
|
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
camera.stop_recording()
|
camera.stop_recording()
|
||||||
|
@ -368,6 +371,7 @@ class CameraPiPlugin(CameraPlugin):
|
||||||
if self._recording_thread:
|
if self._recording_thread:
|
||||||
self._recording_thread.join()
|
self._recording_thread.join()
|
||||||
|
|
||||||
|
# noinspection PyShadowingBuiltins
|
||||||
@action
|
@action
|
||||||
def start_streaming(self, listen_port=5000, format='h264', **opts):
|
def start_streaming(self, listen_port=5000, format='h264', **opts):
|
||||||
"""
|
"""
|
||||||
|
@ -392,6 +396,7 @@ class CameraPiPlugin(CameraPlugin):
|
||||||
server_socket.bind(('0.0.0.0', listen_port))
|
server_socket.bind(('0.0.0.0', listen_port))
|
||||||
server_socket.listen(1)
|
server_socket.listen(1)
|
||||||
|
|
||||||
|
# noinspection PyBroadException
|
||||||
def streaming_thread():
|
def streaming_thread():
|
||||||
try:
|
try:
|
||||||
self.logger.info('Starting streaming on port {}'.format(listen_port))
|
self.logger.info('Starting streaming on port {}'.format(listen_port))
|
||||||
|
@ -412,9 +417,7 @@ class CameraPiPlugin(CameraPlugin):
|
||||||
try:
|
try:
|
||||||
if stream:
|
if stream:
|
||||||
camera.start_recording(stream, format=format)
|
camera.start_recording(stream, format=format)
|
||||||
|
camera.wait_recording()
|
||||||
while not should_stop:
|
|
||||||
camera.wait_recording(1)
|
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
self.logger.info('Client closed connection')
|
self.logger.info('Client closed connection')
|
||||||
finally:
|
finally:
|
||||||
|
@ -445,7 +448,7 @@ class CameraPiPlugin(CameraPlugin):
|
||||||
self._streaming_thread.start()
|
self._streaming_thread.start()
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def stop_streaming(self, **kwargs):
|
def stop_streaming(self):
|
||||||
"""
|
"""
|
||||||
Stop a camera streaming session
|
Stop a camera streaming session
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue