[postprocessor:ugoira] add option for two-pass encoding

This commit is contained in:
Mike Fährmann
2018-06-20 18:48:10 +02:00
parent a9e276bc37
commit 0c1c4557dd
2 changed files with 26 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ from .. import util
import subprocess
import tempfile
import zipfile
import os
class UgoiraPP(PostProcessor):
@@ -20,10 +21,13 @@ class UgoiraPP(PostProcessor):
def __init__(self, pathfmt, options):
PostProcessor.__init__(self)
self.extension = options.get("extension") or "webm"
self.ffmpeg = options.get("ffmpeg-location") or "ffmpeg"
self.args = options.get("ffmpeg-args")
self.twopass = options.get("ffmpeg-twopass")
self.delete = not options.get("keep-files", False)
ffmpeg = options.get("ffmpeg-location")
self.ffmpeg = util.expand_path(ffmpeg) if ffmpeg else "ffmpeg"
def run(self, pathfmt):
if (pathfmt.keywords["extension"] != "zip" or
"frames" not in pathfmt.keywords):
@@ -53,11 +57,18 @@ class UgoiraPP(PostProcessor):
# invoke ffmpeg
pathfmt.set_extension(self.extension)
args = [util.expand_path(self.ffmpeg), "-i", ffconcat]
args = [self.ffmpeg, "-i", ffconcat]
if self.args:
args += self.args
args.append(pathfmt.realpath)
subprocess.Popen(args).wait()
if self.twopass:
log = tempdir + "/ffmpeg2pass"
null = "NUL" if os.name == "nt" else "/dev/null"
args += ["-passlogfile", log, "-pass"]
subprocess.Popen(args + ["1", "-y", null]).wait()
subprocess.Popen(args + ["2", pathfmt.realpath]).wait()
else:
args.append(pathfmt.realpath)
subprocess.Popen(args).wait()
if self.delete:
pathfmt.delete = True