hesabixWpTheme/bin/convert-motion-media.sh

36 lines
1,004 B
Shell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# تبدیل GIFهای صفحه نخست به webm/mp4 (نیاز به ffmpeg)
set -euo pipefail
IMG_DIR="$(cd "$(dirname "$0")/../assets/img" && pwd)"
if ! command -v ffmpeg >/dev/null 2>&1; then
echo "ffmpeg not found. Install ffmpeg and re-run." >&2
exit 1
fi
convert_one() {
local base="$1"
local gif="${IMG_DIR}/${base}.gif"
if [[ ! -f "$gif" ]]; then
echo "skip: $gif"
return
fi
ffmpeg -y -i "$gif" -c:v libvpx-vp9 -b:v 0 -crf 35 -an "${IMG_DIR}/${base}.webm" 2>/dev/null
ffmpeg -y -i "$gif" -c:v libx264 -pix_fmt yuv420p -movflags +faststart -an "${IMG_DIR}/${base}.mp4" 2>/dev/null
echo "done: $base"
}
for name in automation workflow robot ai-robot; do
if [[ -f "${IMG_DIR}/${name}.gif" ]]; then
convert_one "$name"
fi
done
# robot.gif -> ai-robot.*
if [[ -f "${IMG_DIR}/robot.gif" && ! -f "${IMG_DIR}/ai-robot.webm" ]]; then
cp "${IMG_DIR}/robot.gif" "${IMG_DIR}/ai-robot.gif"
convert_one "ai-robot"
fi
echo "Conversion complete."