Changeset - 748ecc2d1f2a
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 6 years ago 2019-06-04 17:19:12
drewp@bigasterisk.com
vidref fix state machine for writing files
Ignore-this: 7f14601f09e4993c99d04a92361a84a6
1 file changed with 14 insertions and 5 deletions:
0 comments (0 inline, 0 general)
light9/vidref/videorecorder.py
Show inline comments
 
@@ -87,18 +87,21 @@ class FramesToVideoFiles:
 
        receive frames (infinite) and wall-to-song times (stream ends with
 
        the song), and write a video file and a frame map
 
        """
 
        return threads.deferToThread(self._bg_save, outBase)
 

	
 
    def _bg_save(self, outBase):
 
        os.makedirs(os.path.dirname(outBase), exist_ok=True)
 
        self.frameMap = open(outBase + '.timing', 'wt')
 

	
 
        # (immediately calls make_frame)
 
        self.currentOutputClip = moviepy.editor.VideoClip(
 
            self._bg_make_frame, duration=999.)
 
        self.currentOutputClip.fps = 5
 
        self.currentOutputClip = moviepy.editor.VideoClip(self._bg_make_frame,
 
                                                          duration=999.)
 
        # The fps recorded in the file doesn't matter much; we'll play
 
        # it back in sync with the music regardless.
 
        self.currentOutputClip.fps = 10
 
        log.info(f'write_videofile {outBase} start')
 
        try:
 
            self.currentOutputClip.write_videofile(outBase + '.mp4',
 
                                                   audio=False,
 
                                                   preset='ultrafast',
 
                                                   logger=None,
 
@@ -108,15 +111,21 @@ class FramesToVideoFiles:
 

	
 
        log.info('write_videofile done')
 
        self.currentOutputClip = None
 

	
 
    def _bg_make_frame(self, video_time_secs):
 
        if self.nextWriteAction == 'close':
 
            raise StopIteration # the one in write_videofile
 
            raise StopIteration  # the one in write_videofile
 
        elif self.nextWriteAction == 'notWritingClip':
 
            raise NotImplementedError
 
        elif self.nextWriteAction == 'saveFrames':
 
            pass
 
        else:
 
            raise NotImplementedError(self.nextWriteAction)
 

	
 
        # should be a queue to miss fewer frames
 
        # should be a little queue to miss fewer frames
 
        while self.nextImg is None:
 
            time.sleep(.03)
 
        cf, self.nextImg = self.nextImg, None
 

	
 
        self.frameMap.write(f'video {video_time_secs:g} = song {cf.t:g}\n')
 
        return numpy.asarray(cf.img)
0 comments (0 inline, 0 general)