added video post-processing
This commit is contained in:
parent
578c25d7bc
commit
60019662b4
2 changed files with 35 additions and 12 deletions
|
@ -1,5 +1,7 @@
|
|||
import imp
|
||||
import logging
|
||||
import os.path
|
||||
import subprocess
|
||||
|
||||
from enum import Enum, auto
|
||||
|
||||
|
@ -67,10 +69,11 @@ class Statemachine:
|
|||
State.PLAY: self._play,
|
||||
State.POST_PROCESS: self._post_process,
|
||||
State.REWIND: self._rewind,
|
||||
State.IDLE_END: self._idle_end
|
||||
State.IDLE_END: self._idle_end,
|
||||
State.SHUTDOWN: self._shutdown
|
||||
}
|
||||
|
||||
while (self.state is not State.ERROR) and (self.state is not State.SHUTDOWN):
|
||||
while (self.state is not State.SHUTDOWN) and (self.state is not State.ERROR):
|
||||
logger.debug(f'Run(state={self.state})')
|
||||
try:
|
||||
choice[self.state]()
|
||||
|
@ -169,10 +172,16 @@ class Statemachine:
|
|||
"""
|
||||
Post-processing
|
||||
"""
|
||||
# TODO postprocessing - add sound
|
||||
# logger.debug('Converting video...')
|
||||
# cmdstring = f'MP4Box -add {fs_names.REC_DRAW_CITY} {fs_names.REC_MERGED_VIDEO}'
|
||||
# call([cmdstring], shell=True)
|
||||
logger.debug('Converting video...')
|
||||
|
||||
for fname in self.story.videos:
|
||||
fnew = fname.split('.')[0] + '.mov'
|
||||
logger.debug(f'Converting {fname} to {fnew}')
|
||||
cmd = ['MP4Box', '-add', fname, fnew]
|
||||
subprocess.run(cmd)
|
||||
cmddel = ['rm', fname]
|
||||
subprocess.run(cmddel)
|
||||
|
||||
self.hal.flush_serial()
|
||||
self._next_state()
|
||||
|
||||
|
@ -190,12 +199,15 @@ class Statemachine:
|
|||
Initialize shutdown or go back to POST if `self.loop=True`
|
||||
"""
|
||||
reset(self.hal)
|
||||
logger.debug('Turning off HELO1...')
|
||||
self.hal.helo1 = False
|
||||
|
||||
logger.debug(f'statemachine.loop={self.loop}')
|
||||
if self.loop:
|
||||
self.state = State.POST
|
||||
else:
|
||||
self._next_state()
|
||||
logger.debug('Setting state to shutdown')
|
||||
self.state = State.SHUTDOWN
|
||||
|
||||
def _shutdown(self):
|
||||
"""
|
||||
|
@ -203,4 +215,5 @@ class Statemachine:
|
|||
"""
|
||||
del self.hal
|
||||
del self.story
|
||||
self.state = None
|
||||
|
||||
|
|
|
@ -66,10 +66,10 @@ class Activity(Enum):
|
|||
RECORD_VIDEO = {'duration': 60.0,
|
||||
'filename': ''}
|
||||
TAKE_PHOTO = {'filename': ''}
|
||||
ADVANCE_UP = {'steps': 48,
|
||||
ADVANCE_UP = {'steps': 47,
|
||||
'scroll': Scrolls.VERTICAL,
|
||||
'speed': 3}
|
||||
ADVANCE_LEFT = {'steps': 92,
|
||||
ADVANCE_LEFT = {'steps': 96,
|
||||
'scroll': Scrolls.HORIZONTAL,
|
||||
'speed': 3}
|
||||
LIGHT_FRONT = {'r': 0,
|
||||
|
@ -202,7 +202,7 @@ def _get_sound(language: Language, **kwargs):
|
|||
|
||||
|
||||
class Storyboard:
|
||||
def __init__(self, *story: List[Do]) -> None:
|
||||
def __init__(self, *story: List[Chapter]) -> None:
|
||||
self.story = story
|
||||
self.hal = None
|
||||
|
||||
|
@ -217,6 +217,8 @@ class Storyboard:
|
|||
|
||||
self._lang = Language.NOT_SET
|
||||
|
||||
self.videos = []
|
||||
|
||||
self.ACTIVITY_SELECTOR = None
|
||||
|
||||
@property
|
||||
|
@ -360,6 +362,11 @@ class Storyboard:
|
|||
if do_now:
|
||||
do_it(hal)
|
||||
|
||||
def _record_video(hal, filename=None, **kwargs):
|
||||
logger.debug(f'Storyboard._record_video(filename={filename}, {kwargs})')
|
||||
record_video(hal, filename=filename, **kwargs)
|
||||
self.videos.append(str(filename))
|
||||
|
||||
def _goto(hal, index:int, **kwargs):
|
||||
"""
|
||||
Set the next chapter
|
||||
|
@ -373,7 +380,7 @@ class Storyboard:
|
|||
Activity.PARALLEL: _parallel,
|
||||
Activity.GOTO: _goto,
|
||||
Activity.RECORD_SOUND: record_sound,
|
||||
Activity.RECORD_VIDEO: record_video,
|
||||
Activity.RECORD_VIDEO: _record_video,
|
||||
Activity.TAKE_PHOTO: take_photo,
|
||||
Activity.LIGHT_FRONT: _light,
|
||||
Activity.LIGHT_BACK: _light,
|
||||
|
@ -399,7 +406,10 @@ class Storyboard:
|
|||
|
||||
if not self._chapter_set:
|
||||
self._chapter_set = True
|
||||
if self._index < (len(self.story) - 1):
|
||||
self._next_chapter = self._index + 1
|
||||
else:
|
||||
self._next_chapter = None
|
||||
|
||||
else:
|
||||
self._next_chapter = None
|
||||
|
|
Loading…
Reference in a new issue