diff --git a/docs/configuration.rst b/docs/configuration.rst index fd076711..acb03d42 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -958,14 +958,13 @@ ugoira.libx264-prevent-odd Type ``bool`` Default ``true`` Description Prevent ``"width/height not divisible by 2"`` errors - when presumably using a ``libx264`` encoder + when using ``libx264`` or ``libx265`` encoders by applying a simple cropping filter. See this `Stack Overflow thread `__ for more information. - If the `filename extension`__ is set to ``mp4`` or ``mkv``, - this option effectively adds - ``["-vf", "crop=iw-mod(iw\\,2):ih-mod(ih\\,2)"]`` + This option, when ``libx264/5`` is used, automatically + adds ``["-vf", "crop=iw-mod(iw\\,2):ih-mod(ih\\,2)"]`` to the list of FFmpeg command-line arguments to reduce an odd width/height by 1 pixel and make them even. =========== ===== diff --git a/gallery_dl/postprocessor/ugoira.py b/gallery_dl/postprocessor/ugoira.py index 753e67ff..17823436 100644 --- a/gallery_dl/postprocessor/ugoira.py +++ b/gallery_dl/postprocessor/ugoira.py @@ -22,7 +22,7 @@ class UgoiraPP(PostProcessor): def __init__(self, pathfmt, options): PostProcessor.__init__(self) self.extension = options.get("extension") or "webm" - self.args = options.get("ffmpeg-args") + self.args = options.get("ffmpeg-args") or () self.twopass = options.get("ffmpeg-twopass", False) self.output = options.get("ffmpeg-output", True) self.delete = not options.get("keep-files", False) @@ -34,9 +34,20 @@ class UgoiraPP(PostProcessor): if rate != "auto": self.calculate_framerate = lambda _: (None, rate) - self.prevent_odd = ( - options.get("libx264-prevent-odd", True) and - self.extension.lower() in ("mp4", "mkv")) + if options.get("libx264-prevent-odd", True): + # get last video-codec argument + vcodec = None + for index, arg in enumerate(self.args): + arg, _, stream = arg.partition(":") + if arg == "-vcodec" or arg in ("-c", "-codec") and ( + not stream or stream.partition(":")[0] in ("v", "V")): + vcodec = self.args[index + 1] + # use filter if libx264/5 is explicitly or implicitly used + self.prevent_odd = ( + vcodec in ("libx264", "libx265") or + not vcodec and self.extension.lower() in ("mp4", "mkv")) + else: + self.prevent_odd = False def run(self, pathfmt): if pathfmt.keywords["extension"] != "zip":