Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real lossless ugoira #1550

Closed
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3751,4 +3751,4 @@ Description
.. _requests.request(): https://requests.readthedocs.io/en/master/api/#requests.request
.. _timeout: https://requests.readthedocs.io/en/master/user/advanced/#timeouts
.. _verify: https://requests.readthedocs.io/en/master/user/advanced/#ssl-cert-verification
.. _`Requests' proxy documentation`: https://requests.readthedocs.io/en/master/user/advanced/#proxies
.. _`Requests' proxy documentation`: https://requests.readthedocs.io/en/master/user/advanced/#proxies
13 changes: 13 additions & 0 deletions gallery_dl/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,19 @@ def build_parser():
},
help="Convert Pixiv Ugoira to WebM in VP9 lossless mode",
)
postprocessor.add_argument(
"--ugoira-conv-copy",
dest="postprocessors", action="append_const", const={
"name" : "ugoira",
"ffmpeg-twopass": False,
"whitelist" : ("pixiv", "danbooru"),
"libx264-prevent-odd": False,
"extension" : "mkv",
"re-encoding" : False,
"repeat-last" : False,
},
help="Convert Pixiv Ugoira to MKV in copy mode (without re-encoding)",
)
postprocessor.add_argument(
"--write-metadata",
dest="postprocessors",
Expand Down
19 changes: 19 additions & 0 deletions gallery_dl/postprocessor/ugoira.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ def convert(self, pathfmt):
else:
args.append(pathfmt.realpath)
self._exec(args)

# test mkvmerge
timecodes = tempdir + "/timecodes.txt"
content = ["# timestamp format v2"]
append = content.append
timecode = 0
append("{}".format(timecode))
for frame in self._frames:
timecode = timecode + frame["delay"]
append("{}".format(timecode))
if self.repeat:
append("{}".format(timecode))
append("")
with open(timecodes, "w") as file:
file.write("\n".join(content))
self._exec("mkvmerge --timecodes 0:{}/timecodes.txt -o {} = {}".format(
tempdir, tempdir + "/mkvmerge.mkv", pathfmt.realpath))
from shutil import move
move(tempdir + "/mkvmerge.mkv", pathfmt.realpath)
except OSError as exc:
print()
self.log.error("Unable to invoke FFmpeg (%s: %s)",
Expand Down