From ed0be42a3ba3026dfaf7cd7fc28ccc0e3f4b9eb7 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 15 Jul 2026 21:59:45 +0000 Subject: [PATCH] th: demote vips (#1556); use libvips as last resort due to risk of OOM; example: libvips defers to imagemagick for animated avif, and imagemagick probably does an identify, iterating through each frame, itself consuming 100+ MiB RAM, which libvips amplifies to 7+ GiB similar behavior is observed with `identify a.mkv` in a shell --- README.md | 4 ++-- contrib/package/arch/PKGBUILD | 2 +- contrib/package/nix/copyparty/default.nix | 2 +- copyparty/__main__.py | 2 +- copyparty/svchub.py | 4 ++-- scripts/docker/README.md | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 12483cf0..a0e6e678 100644 --- a/README.md +++ b/README.md @@ -773,7 +773,7 @@ press `g` or `田` to toggle grid-view instead of the file listing and `t` togg ![copyparty-thumbs-fs8](https://user-images.githubusercontent.com/241032/129636211-abd20fa2-a953-4366-9423-1c88ebb96ba9.png) it does static images with Pillow / pyvips / FFmpeg, and uses FFmpeg for video files, so you may want to `--no-thumb` or maybe just `--no-vthumb` depending on how dangerous your users are -* pyvips is 3x faster than Pillow, Pillow is 3x faster than FFmpeg +* Pillow is 3x faster (and safer) than FFmpeg * disable thumbnails for specific volumes with volflag `dthumb` for all, or `dvthumb` / `dathumb` / `dithumb` for video/audio/images only * for installing FFmpeg on windows, see [optional dependencies](#optional-dependencies) @@ -3241,7 +3241,7 @@ enable sending [zeromq messages](#zeromq) from event-hooks: `pyzmq` enable [smb](#smb-server) support (**not** recommended): `impacket==0.13.0` -`pyvips` gives higher quality thumbnails than `Pillow` and is 320% faster, using 270% more ram +`pyvips` adds support for some additional image formats, but can use extreme amounts of RAM * to install `pyvips` on Linux: `sudo apt install libvips42 && python3 -m pip install --user -U pyvips` * to install `pyvips` on windows: `pip install --user -U "pyvips[binary]"` diff --git a/contrib/package/arch/PKGBUILD b/contrib/package/arch/PKGBUILD index b6ea27bf..9140d1e2 100644 --- a/contrib/package/arch/PKGBUILD +++ b/contrib/package/arch/PKGBUILD @@ -16,7 +16,7 @@ optdepends=("ffmpeg: thumbnails for videos, images (slower) and audio, music tag "python-mutagen: music tags (alternative)" "python-paramiko: sftp server", "python-pillow: thumbnails for images" - "python-pyvips: thumbnails for images (higher quality, faster, uses more ram)" + "python-pyvips: thumbnails for images (eats ram, prefer pillow)" "libkeyfinder: detection of musical keys" "python-pyopenssl: ftps functionality" "python-pyzmq: send zeromq messages from event-hooks" diff --git a/contrib/package/nix/copyparty/default.nix b/contrib/package/nix/copyparty/default.nix index d622ca64..f375e515 100644 --- a/contrib/package/nix/copyparty/default.nix +++ b/contrib/package/nix/copyparty/default.nix @@ -30,7 +30,7 @@ # create thumbnails with Pillow; faster than FFmpeg / MediaProcessing withThumbnails ? true, - # create thumbnails with PyVIPS; even faster, uses more memory + # create thumbnails with PyVIPS; uses more memory, pillow is preferred # -- can be combined with Pillow to support more filetypes withFastThumbnails ? false, diff --git a/copyparty/__main__.py b/copyparty/__main__.py index c28a9fd2..b8cf9df5 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1795,7 +1795,7 @@ def add_thumbnail(ap): ap2.add_argument("--th-x3", metavar="TXT", type=u, default="n", help="show thumbs at 3x resolution; client can override in UI unless force. [\033[32my\033[0m]=yes, [\033[32mn\033[0m]=no, [\033[32mfy\033[0m]=force-yes, [\033[32mfn\033[0m]=force-no (volflag=th3x)") ap2.add_argument("--th-qv", metavar="N", type=int, default=40, help="webp/jpg thumbnail quality (10~90); higher is larger filesize and better quality (volflag=th_qv)") ap2.add_argument("--th-qvx", metavar="N", type=int, default=64, help="jxl thumbnail quality (10~90); higher is larger filesize and better quality (volflag=th_qvx)") - ap2.add_argument("--th-dec", metavar="LIBS", default="vips,raw,pil,ff", help="image decoders, in order of preference") + ap2.add_argument("--th-dec", metavar="LIBS", default="raw,pil,ff,vips", help="image decoders, in order of preference") ap2.add_argument("--th-no-jpg", action="store_true", help="disable jpg output") ap2.add_argument("--th-no-webp", action="store_true", help="disable webp output") ap2.add_argument("--th-no-jxl", action="store_true", help="disable jpeg-xl output") diff --git a/copyparty/svchub.py b/copyparty/svchub.py index d63b6308..933f2def 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -1029,8 +1029,8 @@ class SvcHub(object): # fmt: off to_check = [ (HAVE_SQLITE3, "sqlite", "sessions and file/media indexing"), - (HAVE_PIL, "pillow", "image thumbnails (plenty fast)"), - (HAVE_VIPS, "vips", "image thumbnails (faster, eats more ram)"), + (HAVE_PIL, "pillow", "image thumbnails (good and fast)"), + (HAVE_VIPS, "vips", "image thumbnails (eats ram; will prefer pillow)"), (H_PIL_WEBP, "pillow-webp", "create thumbnails as webp files"), (HAVE_FFMPEG, "ffmpeg", t_ff + ", good-but-slow image thumbnails"), (HAVE_FFPROBE, "ffprobe", t_ff + ", read audio/media tags"), diff --git a/scripts/docker/README.md b/scripts/docker/README.md index 37f756e9..7d4473a5 100644 --- a/scripts/docker/README.md +++ b/scripts/docker/README.md @@ -49,7 +49,7 @@ with image size after installation and when gzipped * [`min`](https://hub.docker.com/r/copyparty/min) (57 MiB, 20 gz) is just copyparty itself * [`im`](https://hub.docker.com/r/copyparty/im) (70 MiB, 25 gz) can thumbnail images with pillow, parse media files with mutagen * [`ac` (163 MiB, 56 gz)](https://hub.docker.com/r/copyparty/ac) is `im` plus ffmpeg for video/audio thumbs + audio transcoding + better tags -* [`iv`](https://hub.docker.com/r/copyparty/iv) (211 MiB, 73 gz) is `ac` plus vips for faster heif / avic / jxl thumbnails +* [`iv`](https://hub.docker.com/r/copyparty/iv) (211 MiB, 73 gz) is `ac` plus vips for more thumbnail formats * [`dj`](https://hub.docker.com/r/copyparty/dj) (309 MiB, 104 gz) is `iv` plus beatroot/keyfinder to detect musical keys and bpm [`ac` is recommended](https://hub.docker.com/r/copyparty/ac) since the additional features available in `iv` and `dj` are rarely useful