[pp:ugoira] fix processing '.gif' frames
use 'concat' demuxer to combine frames for mkvmerge https://github.com/danbooru/danbooru/pull/6103 https://github.com/danbooru/danbooru/pull/6241
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2018-2025 Mike Fährmann
|
# Copyright 2018-2026 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -352,14 +352,13 @@ class UgoiraPP(PostProcessor):
|
|||||||
|
|
||||||
def _process_mkvmerge(self, pathfmt, tempdir):
|
def _process_mkvmerge(self, pathfmt, tempdir):
|
||||||
self._realpath = pathfmt.realpath
|
self._realpath = pathfmt.realpath
|
||||||
pathfmt.realpath = tempdir + "/temp." + self.extension
|
pathfmt.realpath = f"{tempdir}/temp.{self.extension}"
|
||||||
|
|
||||||
return [
|
return [
|
||||||
self.ffmpeg,
|
self.ffmpeg,
|
||||||
"-f", "image2",
|
"-r", "25",
|
||||||
"-pattern_type", "sequence",
|
"-f", "concat",
|
||||||
"-i", (f"{tempdir.replace('%', '%%')}/%06d."
|
"-i", self._write_ffmpeg_concat(tempdir, False),
|
||||||
f"{self._frames[0]['file'].rpartition('.')[2]}"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def _finalize_mkvmerge(self, pathfmt, tempdir):
|
def _finalize_mkvmerge(self, pathfmt, tempdir):
|
||||||
@@ -375,12 +374,16 @@ class UgoiraPP(PostProcessor):
|
|||||||
pathfmt.realpath = self._realpath
|
pathfmt.realpath = self._realpath
|
||||||
self._exec(args)
|
self._exec(args)
|
||||||
|
|
||||||
def _write_ffmpeg_concat(self, tempdir):
|
def _write_ffmpeg_concat(self, tempdir, duration=True):
|
||||||
content = ["ffconcat version 1.0"]
|
content = ["ffconcat version 1.0"]
|
||||||
|
|
||||||
for frame in self._frames:
|
if duration:
|
||||||
content.append(f"file '{frame['file']}'\n"
|
for frame in self._frames:
|
||||||
f"duration {frame['delay'] / 1000}")
|
content.append(f"file '{frame['file']}'\n"
|
||||||
|
f"duration {frame['delay'] / 1000}")
|
||||||
|
else:
|
||||||
|
for frame in self._frames:
|
||||||
|
content.append(f"file '{frame['file']}'")
|
||||||
if self.repeat:
|
if self.repeat:
|
||||||
content.append(f"file '{frame['file']}'")
|
content.append(f"file '{frame['file']}'")
|
||||||
content.append("")
|
content.append("")
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ __tests__ = (
|
|||||||
|
|
||||||
{
|
{
|
||||||
"#url" : "https://www.pixiv.net/artworks/101003492",
|
"#url" : "https://www.pixiv.net/artworks/101003492",
|
||||||
"#comment" : "original ugoira frames (#6056)",
|
"#comment" : "ugoira - original '.png' frames (#6056)",
|
||||||
"#class" : pixiv.PixivWorkExtractor,
|
"#class" : pixiv.PixivWorkExtractor,
|
||||||
"#options" : {"ugoira": "original"},
|
"#options" : {"ugoira": "original"},
|
||||||
"#results" : (
|
"#results" : (
|
||||||
@@ -292,6 +292,18 @@ __tests__ = (
|
|||||||
"count" : 6,
|
"count" : 6,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"#url" : "https://www.pixiv.net/en/artworks/108469527",
|
||||||
|
"#comment" : "ugoira - '.gif' frames",
|
||||||
|
"#class" : pixiv.PixivWorkExtractor,
|
||||||
|
"#options" : {"ugoira": "original"},
|
||||||
|
"#pattern" : r"https://i\.pximg\.net/img\-original/img/2023/05/27/02/23/48/108469527_ugoira\d+\.gif",
|
||||||
|
"#count" : 30,
|
||||||
|
|
||||||
|
"frames": list,
|
||||||
|
"count" : 30,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"#url" : "https://www.pixiv.net/artworks/966412",
|
"#url" : "https://www.pixiv.net/artworks/966412",
|
||||||
"#comment" : "related works (#1237)",
|
"#comment" : "related works (#1237)",
|
||||||
|
|||||||
Reference in New Issue
Block a user