diff options
| author | Christopher Warner <cwarner@kernelcode.com> | 2026-10-13 15:07:53 -0400 |
|---|---|---|
| committer | Christopher Warner <cwarner@kernelcode.com> | 2026-10-13 15:07:53 -0400 |
| commit | 6f3426c481f03f5beeed9171b3280f0070798844 (patch) | |
| tree | c2cfb41a3a8f17919aa40d76ccf032546165ab75 /bin/encode-aerial-lite | |
| parent | ead35d75893dcbc34a97beb165a2d46f7741bfc8 (diff) | |
| download | aerial-screensaver-linux-6f3426c481f03f5beeed9171b3280f0070798844.tar.gz aerial-screensaver-linux-6f3426c481f03f5beeed9171b3280f0070798844.tar.bz2 aerial-screensaver-linux-6f3426c481f03f5beeed9171b3280f0070798844.tar.xz aerial-screensaver-linux-6f3426c481f03f5beeed9171b3280f0070798844.zip | |
feat: package portable Aerial screensaver for sharing
Add install/uninstall scripts, XDG config, portable VAAPI detection,
fetch-aerial-recent helper, and a LocalSend-ready zip without Apple video assets.
Co-authored-by: Cursor <cursoragent@cursor.com>
Diffstat (limited to 'bin/encode-aerial-lite')
| -rwxr-xr-x | bin/encode-aerial-lite | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/bin/encode-aerial-lite b/bin/encode-aerial-lite new file mode 100755 index 0000000..58976af --- /dev/null +++ b/bin/encode-aerial-lite @@ -0,0 +1,130 @@ +#!/usr/bin/env bash +# Downsample Aerial masters into ~/Videos/Screensavers/Aerial: +# 1920x1080, 24fps, 8-bit HEVC via VAAPI (~2 Mb/s). +# +# Usage: +# encode-aerial-lite /path/to/4k-sources +# SRC_DIR=/path/to/4k DST_DIR=~/Videos/Screensavers/Aerial encode-aerial-lite +set -euo pipefail + +SRC_DIR="${1:-${SRC_DIR:-}}" +DST_DIR="${DST_DIR:-$HOME/Videos/Screensavers/Aerial}" +CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/aerial-screensaver/config" +BITRATE="${BITRATE:-2M}" +MAXRATE="${MAXRATE:-2.5M}" + +detect_vaapi() { + if [[ -n "${VAAPI_DEVICE:-}" && -e "$VAAPI_DEVICE" ]]; then + printf '%s\n' "$VAAPI_DEVICE" + return 0 + fi + if [[ -f "$CONFIG_FILE" ]]; then + local from_cfg + from_cfg="$(awk -F= '/^VAAPI_DEVICE=/{print $2; exit}' "$CONFIG_FILE" | tr -d '"' || true)" + if [[ -n "$from_cfg" && -e "$from_cfg" ]]; then + printf '%s\n' "$from_cfg" + return 0 + fi + fi + local p + if [[ -d /dev/dri/by-path ]]; then + for p in /dev/dri/by-path/*-render; do + [[ -e "$p" ]] || continue + [[ "$(basename "$p")" == *usb* ]] && continue + printf '%s\n' "$p" + return 0 + done + fi + for p in /dev/dri/renderD*; do + [[ -e "$p" ]] || continue + printf '%s\n' "$p" + return 0 + done + return 1 +} + +if [[ -z "$SRC_DIR" ]]; then + echo "Usage: encode-aerial-lite /path/to/4k-source-folder" >&2 + echo "Encodes into: $DST_DIR" >&2 + exit 1 +fi + +VAAPI_DEVICE="$(detect_vaapi)" || { + echo "No VAAPI render node found. Set VAAPI_DEVICE=/dev/dri/renderD128" >&2 + exit 1 +} + +mkdir -p "$DST_DIR" +shopt -s nullglob nocaseglob + +encode_one() { + local src="$1" + local base dest tmp + base="$(basename "$src")" + base="${base%.*}" + dest="$DST_DIR/${base}.mp4" + + if [[ -f "$dest" ]]; then + echo "SKIP $base (exists)" + return 0 + fi + + echo "ENCODE $base" + tmp="$DST_DIR/.${base}.partial.mp4" + rm -f "$tmp" + + if ffmpeg -y -hide_banner -loglevel error -stats \ + -hwaccel vaapi -hwaccel_device "$VAAPI_DEVICE" -hwaccel_output_format vaapi \ + -i "$src" \ + -vf "fps=24,scale_vaapi=w=1920:h=1080:format=nv12" \ + -c:v hevc_vaapi -b:v "$BITRATE" -maxrate "$MAXRATE" -bufsize 4M \ + -an -movflags +faststart \ + "$tmp"; then + mv -f "$tmp" "$dest" + echo "OK $base ($(du -h "$dest" | cut -f1))" + else + echo "FAIL $base — retrying with software decode" >&2 + rm -f "$tmp" + if ffmpeg -y -hide_banner -loglevel error -stats \ + -vaapi_device "$VAAPI_DEVICE" \ + -i "$src" \ + -vf "fps=24,scale=1920:1080:flags=bicubic,format=nv12,hwupload" \ + -c:v hevc_vaapi -b:v "$BITRATE" -maxrate "$MAXRATE" -bufsize 4M \ + -an -movflags +faststart \ + "$tmp"; then + mv -f "$tmp" "$dest" + echo "OK $base (sw-decode, $(du -h "$dest" | cut -f1))" + else + rm -f "$tmp" + echo "FAIL $base" >&2 + return 1 + fi + fi +} + +shopt -u nocaseglob +mapfile -t files < <(find "$SRC_DIR" -maxdepth 1 -type f \( -iname '*.mov' -o -iname '*.mp4' -o -iname '*.mkv' \) | sort) +if [[ ${#files[@]} -eq 0 ]]; then + echo "No source videos in $SRC_DIR" >&2 + exit 1 +fi + +echo "Source: $SRC_DIR (${#files[@]} files)" +echo "Dest: $DST_DIR" +echo "Device: $VAAPI_DEVICE" +echo + +failures=0 +for f in "${files[@]}"; do + if ! encode_one "$f"; then + failures=$((failures + 1)) + fi +done + +rm -f "$DST_DIR/_test_lite.mp4" "$DST_DIR"/.*.partial.mp4 + +echo +echo "Done. Lite library:" +ls -lh "$DST_DIR" +du -sh "$DST_DIR" +exit "$failures" |
