Files
iptvnator/spikes/mpv-frame-copy/run.sh
T
4grayandClaude Fable 5 10cf157f79 spike(embedded-mpv): frame-copy pipeline prototype (helper + shm ring + Electron viewer)
Standalone macOS spike for the frame-copy unification direction from the
2026-07-10 analysis: a helper process renders mpv offscreen into a GL FBO,
reads frames back through an async PBO ring, and publishes BGRA frames into
a 3-slot POSIX shm seqlock ring; a minimal Electron viewer copies the newest
frame via a plain-C N-API addon and uploads it to a WebGL canvas per rAF.

First numbers on M1 Pro (see spike README): 4K60 HEVC hwdec sustained at
60 fps end to end, ~1.2 ms shm copy + ~3.5 ms texture upload, ~10 ms
produce-to-upload age, zero torn frames. Remaining gates: weak hardware,
long-run pacing, HDR, latency flash test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-15 18:20:45 +02:00

39 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build and run the full spike: helper (producer) + Electron viewer (consumer).
#
# ./run.sh <media-url-or-path> [WxH]
# ./run.sh 'av://lavfi:testsrc2=size=1920x1080:rate=60' 1920x1080
#
# Env overrides: ELECTRON (viewer binary), SPIKE_SHM (ring name),
# HELPER_ARGS (extra helper flags, e.g. "--hwdec videotoolbox-copy --loop").
set -euo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"
MEDIA="${1:?usage: run.sh <media-url-or-path> [WxH]}"
SIZE="${2:-1920x1080}"
SHM="${SPIKE_SHM:-/mpv-frame-spike}"
make -C "$DIR"
if [[ -z "${ELECTRON:-}" ]]; then
for candidate in \
"$DIR/../../node_modules/.bin/electron" \
"$DIR/../../../../../node_modules/.bin/electron"; do
if [[ -x "$candidate" ]]; then
ELECTRON="$candidate"
break
fi
done
fi
if [[ -z "${ELECTRON:-}" ]]; then
echo "electron binary not found; set ELECTRON=/path/to/electron" >&2
exit 1
fi
# shellcheck disable=SC2086
"$DIR/build/mpv_helper" "$MEDIA" --size "$SIZE" --shm "$SHM" ${HELPER_ARGS:-} &
HELPER_PID=$!
trap 'kill "$HELPER_PID" 2>/dev/null || true' EXIT
SPIKE_SHM="$SHM" "$ELECTRON" "$DIR/viewer/main.js"