From a2f5be375c0f0f44d9cb869c67c7970f04afdb4a Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 17 Feb 2022 08:48:03 +0100 Subject: [PATCH] Add apng2webp --- README.md | 1 + apng2webp.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 apng2webp.sh diff --git a/README.md b/README.md index 8712bde..1c5e3e5 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,4 @@ | yt2mpd.sh | Adds an Youtube video to MPD, with correct title and duration. | | fetch_gaidao.sh | Auf neue Ausgaben von der Gai Dao prüfen, herunterladen. | | srtadrm | Remove ads from SRT files with a list of POSIX extended regular expressions. | +| apng2webp.sh | Convert animated PNG to animated WebP | diff --git a/apng2webp.sh b/apng2webp.sh new file mode 100755 index 0000000..4b29567 --- /dev/null +++ b/apng2webp.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# Convert animated PNG to animated WebP. Maximum compression no blend. + +set -euo pipefail + +if [[ $# -lt 2 ]]; then + echo "Usage: ${0} input.png output.webp" >&2 + exit 1 +fi +input="$(realpath "${1}")" +output="$(realpath "${2}")" + +mkdir -p apng2webp_work +pushd apng2webp_work + +mkdir -p apngdis +pushd apngdis +cp "${input}" "input.png" +apngdis "input.png" +popd + +counter=1 +for file in apngdis/apngframe*.png; do + # shellcheck disable=2086 + cwebp -lossless -q 100 "${file}" -o "$(printf "%02d" ${counter}).webp" + counter=$((counter+1)) +done + +webpmux_options="" +counter=1 +for file in apngdis/apngframe*.txt; do + delay=$(grep -Po '=\d+/' "${file}") + delay="${delay:1:-1}" + webpmux_options="${webpmux_options} -frame $(printf "%02d" ${counter}).webp +${delay}+0+0+0-b" + counter=$((counter+1)) +done + +# shellcheck disable=2086 +webpmux ${webpmux_options} -o "${output}" + +popd +rm -r apng2webp_work