From bb50e857959638f6cead9f984d18eaf0e465c5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 27 May 2021 21:48:30 +0200 Subject: [PATCH] [postprocessor:ugoira] optimize writing ffconcat files collect all content in-memory first and write everything with a single 'write()' --- gallery_dl/postprocessor/ugoira.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gallery_dl/postprocessor/ugoira.py b/gallery_dl/postprocessor/ugoira.py index 74cac884..ac094b7c 100644 --- a/gallery_dl/postprocessor/ugoira.py +++ b/gallery_dl/postprocessor/ugoira.py @@ -117,15 +117,19 @@ class UgoiraPP(PostProcessor): pathfmt.set_extension("zip") def _concat(self, path): - # write ffconcat file ffconcat = path + "/ffconcat.txt" + + content = ["ffconcat version 1.0"] + append = content.append + for frame in self._frames: + append("file '{}'\nduration {}".format( + frame["file"], frame["delay"] / 1000)) + if self.repeat: + append("file '{}'".format(frame["file"])) + append("") + with open(ffconcat, "w") as file: - file.write("ffconcat version 1.0\n") - for frame in self._frames: - file.write("file '{}'\n".format(frame["file"])) - file.write("duration {}\n".format(frame["delay"] / 1000)) - if self.repeat: - file.write("file '{}'\n".format(frame["file"])) + file.write("\n".join(content)) rate_in, rate_out = self.calculate_framerate(self._frames) args = [self.ffmpeg, "-f", "concat"]