changeset 1943:748ecc2d1f2a

vidref fix state machine for writing files Ignore-this: 7f14601f09e4993c99d04a92361a84a6
author drewp@bigasterisk.com
date Tue, 04 Jun 2019 17:19:12 +0000
parents 82e98aa4d159
children b0691e922fa1
files light9/vidref/videorecorder.py
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/light9/vidref/videorecorder.py	Tue Jun 04 17:17:55 2019 +0000
+++ b/light9/vidref/videorecorder.py	Tue Jun 04 17:19:12 2019 +0000
@@ -90,12 +90,15 @@
         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',
@@ -111,9 +114,15 @@
 
     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