Skip to content

Commit

Permalink
Parallel screenshot/audio generation
Browse files Browse the repository at this point in the history
  • Loading branch information
RicBent committed Sep 30, 2021
1 parent 4a53362 commit 13e3c05
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions utils/ankiexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand All @@ -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)

0 comments on commit 13e3c05

Please sign in to comment.