Add apng2webp
This commit is contained in:
parent
a93eb2dfbf
commit
a2f5be375c
|
@ -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 |
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue