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

Add mkv ugoira packing without encoding #1218

Merged
merged 9 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions PixivConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ class PixivConfig():
ConfigItem("FFmpeg", "ffmpegCodec", "libvpx-vp9"),
ConfigItem("FFmpeg", "ffmpegExt", "webm"),
ConfigItem("FFmpeg", "ffmpegParam", "-lossless 0 -crf 15 -b 0 -vsync 0"),
ConfigItem("FFmpeg", "mkvCodec", "copy"),
ConfigItem("FFmpeg", "mkvParam", ""),
ConfigItem("FFmpeg", "webpCodec", "libwebp"),
ConfigItem("FFmpeg", "webpParam", "-lossless 0 -compression_level 5 -quality 100 -loop 0 -vsync 0"),
ConfigItem("FFmpeg", "gifParam",
Expand All @@ -187,6 +189,7 @@ class PixivConfig():

ConfigItem("Ugoira", "writeUgoiraInfo", False),
ConfigItem("Ugoira", "createUgoira", False),
ConfigItem("Ugoira", "createMkv", False),
ConfigItem("Ugoira", "createWebm", False),
ConfigItem("Ugoira", "createWebp", False),
ConfigItem("Ugoira", "createGif", False),
Expand Down
11 changes: 10 additions & 1 deletion PixivDownloadHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def download_image(caller,
remote_file_size = get_remote_filesize(url, referer, config, notifier)
else:
remote_file_size = -1
PixivHelper.print_and_log(None, f"\rSkipped getting remote file size because local file not exists")
PixivHelper.print_and_log(None, "\rSkipped getting remote file size because local file not exists")

# 837
if config.skipUnknownSize and is_exists and remote_file_size == -1:
Expand Down Expand Up @@ -426,13 +426,22 @@ def handle_ugoira(image, zip_filename, config, notifier):
codec=config.ffmpegCodec,
extension=config.ffmpegExt,
image=image)

if config.createWebp:
webp_filename = ugo_name[:-7] + ".webp"
if not os.path.exists(webp_filename):
PixivHelper.ugoira2webp(ugo_name,
webp_filename,
image=image)

if config.createMkv:
mkv_filename = ugo_name[:-7] + ".mkv"
if not os.path.exists(mkv_filename):
PixivHelper.ugoira2mkv(ugo_name,
mkv_filename,
codec=config.mkvCodec,
image=image)

if config.deleteZipFile and os.path.exists(zip_filename) and zip_filename.endswith(".zip"):
PixivHelper.print_and_log('info', f"Deleting zip file => {zip_filename}")
os.remove(zip_filename)
Expand Down
11 changes: 11 additions & 0 deletions PixivHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,17 @@ def ugoira2webm(ugoira_file, exportname, codec="libvpx-vp9", extension="webm", i
image=image)


def ugoira2mkv(ugoira_file, exportname, codec="copy", image=None):
print_and_log('info', 'Processing ugoira to mkv...')
convert_ugoira(ugoira_file,
exportname,
ffmpeg=_config.ffmpeg,
codec=codec,
param=_config.mkvParam,
extension="mkv",
image=image)


def convert_ugoira(ugoira_file, exportname, ffmpeg, codec, param, extension, image=None):
''' modified based on https://github.com/tsudoko/ugoira-tools/blob/master/ugoira2webm/ugoira2webm.py '''
# if not os.path.exists(os.path.abspath(ffmpeg)):
Expand Down
1 change: 1 addition & 0 deletions PixivImageHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ def process_ugoira_local(caller, config):
file_basename = os.path.basename(file)
file_ext = os.path.splitext(file_basename)[1]
if ((("gif" in file_ext) and (config.createGif))
or (("mkv" in file_ext) and (config.createMkv))
or (("png" in file_ext) and (config.createApng))
or (("webm" in file_ext) and (config.createWebm))
or (("webp" in file_ext) and (config.createWebp))
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,12 @@ Please refer run with `--help` for latest information.
- ffmpegparam

Parameter to be used to encode webm, default: `-lossless 0 -crf 15 -b 0 -vsync 0`.
- mkvcodec

Codec to be used for encoding mkv, default is using `copy`.
- mkvparam

Parameter to be used to encode mkv, default: ` `.
- webpcodec

Codec to be used for encoding webm, default is using `libwebp`.
Expand All @@ -640,6 +646,10 @@ Please refer run with `--help` for latest information.

If set to `True`, it will create .ugoira file.
This is Pixiv own format for animated images. You can use Honeyview to see the animation.
- createmkv

Set to True to create mkv file (video format). The default settings is lossless(no encoding), it will pack the images in the container. Very large file size.
Required `createUgoira = True` and ffmpeg executeable.
- createwebm

Set to True to create webm file (video format). The default encoding settings is lossy encoding but high quality with smallest file size.
Expand Down