[postprocessor:ugoira] optimize writing ffconcat files

collect all content in-memory first and
write everything with a single 'write()'
pull/1633/head
Mike Fährmann 3 years ago
parent 5c18db5fab
commit bb50e85795
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -117,15 +117,19 @@ class UgoiraPP(PostProcessor):
pathfmt.set_extension("zip") pathfmt.set_extension("zip")
def _concat(self, path): def _concat(self, path):
# write ffconcat file
ffconcat = path + "/ffconcat.txt" 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: with open(ffconcat, "w") as file:
file.write("ffconcat version 1.0\n") file.write("\n".join(content))
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"]))
rate_in, rate_out = self.calculate_framerate(self._frames) rate_in, rate_out = self.calculate_framerate(self._frames)
args = [self.ffmpeg, "-f", "concat"] args = [self.ffmpeg, "-f", "concat"]

Loading…
Cancel
Save