From 13e3c05b70eb7b160f8dbf217b8166b0b97186cf Mon Sep 17 00:00:00 2001 From: Bent Date: Thu, 30 Sep 2021 23:19:06 +0200 Subject: [PATCH] Parallel screenshot/audio generation --- utils/ankiexport.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/utils/ankiexport.py b/utils/ankiexport.py index 5e7f01e..ca8f340 100644 --- a/utils/ankiexport.py +++ b/utils/ankiexport.py @@ -40,8 +40,10 @@ def export_card(self, media_file, audio_track, text, time_start, time_end, unkno audio_path = self.tmp_dir + '/' + audio_name audio_path = os.path.normpath(audio_path) - self.make_audio(media_file, audio_track, time_start, time_end, audio_path) - self.make_snapshot(media_file, time_start, time_end, img_path) + audio_proc = self.make_audio(media_file, audio_track, time_start, time_end, audio_path) + screenshot_proc = self.make_snapshot(media_file, time_start, time_end, img_path) + audio_proc.wait() + screenshot_proc.wait() try: img_file = open(img_path,'rb') @@ -87,10 +89,7 @@ def make_audio(self, media_file, audio_track, start, end, out_path): '--start=' + str(start), '--end=' + str(end), '--o=' + out_path] - print('CARDEXP:', args) - r = subprocess.run(args, cwd=self.mpv_cwd) - print('CARDEXP:', r) - return r + return subprocess.Popen(args, cwd=self.mpv_cwd) def make_snapshot(self, media_file, start, end, out_path): @@ -116,7 +115,4 @@ def make_snapshot(self, media_file, start, end, out_path): scale_arg = '--vf-add=scale=w=%d:h=%d:force_original_aspect_ratio=decrease' % (w, h) args.append(scale_arg) - print('CARDEXP:', args) - r = subprocess.run(args, cwd=self.mpv_cwd) - print('CARDEXP:', r) - return r + return subprocess.Popen(args, cwd=self.mpv_cwd)