Open-source AI podcast clipper. Generate vertical clips with face tracking and burned-in captions. CLI, MCP server, web app.
Python ai-toolsauto-captionscaptionscliffmpegmcpmcp-serveropusclip-alternativepodcast-clipspodcastsshortform-videovertical-videowhisper
Serve native arm64 ffmpeg on Apple Silicon; re-provision wrong-arch runtimes (#102)
Nika Siradze1a5d87653f33
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 7d9633c..43e8772 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -7,6 +7,33 @@ on:branches: [main]jobs:+ go:+ name: Go build + test+ runs-on: ${{ matrix.os }}+ strategy:+ fail-fast: false+ matrix:+ os: [ubuntu-latest, macos-latest, windows-latest]+ steps:+ - uses: actions/checkout@v7+ - uses: actions/setup-go@v5+ with:+ go-version: '1.23'+ cache: false # stdlib-only module: no go.sum to key a cache on+ - name: Sync embedded backend + PodStack commands+ working-directory: cli+ shell: bash # go:generate shells out to `sh sync.sh`, which needs sh on PATH+ run: go generate ./... # files/ and commands/ are generated, not committed; go:embed fails without them+ - name: Build+ working-directory: cli+ run: go build ./...+ - name: Vet+ working-directory: cli+ run: go vet ./...+ - name: Test+ working-directory: cli+ run: go test ./...+typescript:name: TypeScript build + typecheckruns-on: ${{ matrix.os }}diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex eca34ab..2b201f8 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -97,6 +97,66 @@ jobs:name: ${{ env.ASSET }}path: ${{ env.ASSET }}+ # Apple Silicon only. Linux and Windows already get correct native builds from+ # the static sources the provisioner uses; macOS has no upstream arm64 static,+ # and the URL we pointed at serves x86_64 to every Mac, so ffmpeg ran under+ # Rosetta at roughly a third of native encode speed.+ ffmpeg-darwin:+ runs-on: macos-14+ env:+ FFMPEG_VERSION: '7.1'+ FFMPEG_SHA256: 40973d44970dbc83ef302b0609f2e74982be2d85916dd2ee7472d30678a7abe6+ X264_COMMIT: b35605ace3ddf7c1a5d67a2eb553f034aef41d55 # stable as of 2026-07-12+ steps:+ - name: Build ffmpeg (arm64, static libx264)+ shell: bash+ run: |+ set -euo pipefail+ brew install --quiet nasm pkg-config+ deps="$GITHUB_WORKSPACE/deps"+ # Pin x264 by commit: "stable" moves, and whatever it points at ends up+ # inside a binary we hand to users. Static-only because Homebrew's prefix+ # carries libx264.dylib next to the .a and ld prefers the dylib, which+ # would bake a Homebrew path into a binary shipped to machines with no+ # Homebrew.+ git clone -q https://code.videolan.org/videolan/x264.git+ git -C x264 checkout -q "$X264_COMMIT"+ (cd x264 && ./configure --prefix="$deps" --enable-static --enable-pic --disable-cli && make -j"$(sysctl -n hw.ncpu)" && make install)+ curl -fsSL "https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz" -o ffmpeg.tar.xz+ # ffmpeg.org publishes no checksum file, so pin the digest here: an+ # unverified tarball would compile straight into a release asset.+ echo "${FFMPEG_SHA256} ffmpeg.tar.xz" | shasum -a 256 -c -+ tar xf ffmpeg.tar.xz && cd "ffmpeg-${FFMPEG_VERSION}"+ PKG_CONFIG_PATH="$deps/lib/pkgconfig" ./configure \+ --enable-gpl --enable-libx264 \+ --pkg-config-flags=--static \+ --extra-cflags="-I$deps/include" --extra-ldflags="-L$deps/lib" \+ --disable-shared --enable-static \+ --disable-doc --disable-debug --disable-ffplay+ make -j"$(sysctl -n hw.ncpu)" ffmpeg ffprobe+ cd ..+ cp "ffmpeg-${FFMPEG_VERSION}/ffmpeg" ffmpeg-darwin-arm64+ cp "ffmpeg-${FFMPEG_VERSION}/ffprobe" ffprobe-darwin-arm64+ - name: Verify the binaries are native and self-contained+ shell: bash+ run: |+ set -euo pipefail+ for b in ffmpeg-darwin-arm64 ffprobe-darwin-arm64; do+ # lipo, not `file | grep arm64`: that also matches a universal binary+ # carrying an x86_64 slice, which is what we are trying to stop shipping.+ [ "$(lipo -archs "$b")" = "arm64" ] || { echo "$b is not arm64-only: $(lipo -archs "$b")"; exit 1; }+ if otool -L "$b" | tail -n +2 | grep -qv -e '/usr/lib/' -e '/System/'; then+ echo "$b links a non-system library:"; otool -L "$b"; exit 1+ fi+ done+ ./ffmpeg-darwin-arm64 -hide_banner -encoders | grep -q libx264+ - uses: actions/upload-artifact@v7+ with:+ name: ffmpeg-darwin-arm64+ path: |+ ffmpeg-darwin-arm64+ ffprobe-darwin-arm64+studio:runs-on: ubuntu-lateststeps:@@ -145,7 +205,7 @@ jobs:path: ${{ env.ASSET }}release:- needs: [build, whisper, studio, remotion]+ needs: [build, whisper, studio, remotion, ffmpeg-darwin]runs-on: ubuntu-latestpermissions:contents: writediff --git a/cli/internal/backend/sync.sh b/cli/internal/backend/sync.shindex 51ca2ac..bace2d9 100644--- a/cli/internal/backend/sync.sh+++ b/cli/internal/backend/sync.sh@@ -7,13 +7,17 @@ src="$here/../../../backend"dest="$here/files"rm -rf "$dest"mkdir -p "$dest"-rsync -a \- --exclude='__pycache__' \- --exclude='*.pyc' \- --exclude='venv' \- --exclude='.venv' \- --exclude='requirements.txt' \- --exclude='models/res10_300x300_ssd_iter_140000.caffemodel' \- --exclude='models/deploy.prototxt' \- "$src"/ "$dest"/+# Plain cp: this runs wherever `go generate` does, and on Windows Git Bash has+# no rsync while its tar reads the leading "D:" of an absolute path as a remote+# host. Skip venv before copying rather than deleting it afterwards.+for entry in "$src"/*; do+ case "${entry##*/}" in+ venv | .venv | requirements.txt) continue ;;+ esac+ cp -R "$entry" "$dest"/+done+rm -f "$dest/models/res10_300x300_ssd_iter_140000.caffemodel" \+ "$dest/models/deploy.prototxt"+find "$dest" -name '__pycache__' -type d -prune -exec rm -rf {} ++find "$dest" -name '*.pyc' -deleteecho "synced backend -> $dest"diff --git a/cli/internal/provision/arch.go b/cli/internal/provision/arch.gonew file mode 100644index 0000000..7e601d1--- /dev/null+++ b/cli/internal/provision/arch.go@@ -0,0 +1,57 @@+package provision++import (+ "debug/elf"+ "debug/macho"+ "debug/pe"+ "runtime"+)++// nativeArch reports the GOARCH an executable was built for. ok is false when+// the format is unrecognised (scripts, universal binaries), so callers can tell+// "wrong arch" apart from "cannot tell".+func nativeArch(path string) (arch string, ok bool) {+ if f, err := macho.Open(path); err == nil {+ defer f.Close()+ switch f.Cpu {+ case macho.CpuAmd64:+ return "amd64", true+ case macho.CpuArm64:+ return "arm64", true+ }+ return "", false+ }+ if f, err := elf.Open(path); err == nil {+ defer f.Close()+ switch f.Machine {+ case elf.EM_X86_64:+ return "amd64", true+ case elf.EM_AARCH64:+ return "arm64", true+ }+ return "", false+ }+ if f, err := pe.Open(path); err == nil {+ defer f.Close()+ switch f.Machine {+ case pe.IMAGE_FILE_MACHINE_AMD64:+ return "amd64", true+ case pe.IMAGE_FILE_MACHINE_ARM64:+ return "arm64", true+ }+ return "", false+ }+ return "", false+}++// nativeBin reports whether path exists and runs natively here. Existence alone+// is not enough: a runtime provisioned by an earlier install can hold binaries+// for the wrong arch, which run under emulation at best, and on macOS pin pip to+// x86_64 wheels that upstream no longer publishes. Callers re-provision instead.+func nativeBin(path string) bool {+ if !have(path) {+ return false+ }+ arch, ok := nativeArch(path)+ return !ok || arch == runtime.GOARCH+}diff --git a/cli/internal/provision/arch_test.go b/cli/internal/provision/arch_test.gonew file mode 100644index 0000000..6e10515--- /dev/null+++ b/cli/internal/provision/arch_test.go@@ -0,0 +1,84 @@+package provision++import (+ "os"+ "os/exec"+ "path/filepath"+ "runtime"+ "testing"+)++// Cross-compiling a trivial program gives the test real Mach-O, ELF and PE+// headers to read, rather than hand-rolled fixtures that could agree with a+// broken parser.+func buildFor(t *testing.T, goos, goarch string) string {+ t.Helper()+ dir := t.TempDir()+ write := func(name, body string) {+ if err := os.WriteFile(filepath.Join(dir, name), []byte(body), 0o644); err != nil {+ t.Fatal(err)+ }+ }+ write("go.mod", "module archprobe\n\ngo 1.21\n")+ write("main.go", "package main\n\nfunc main() {}\n")++ out := filepath.Join(dir, "probe")+ cmd := exec.Command("go", "build", "-o", out, ".")+ cmd.Dir = dir+ cmd.Env = append(os.Environ(), "GOOS="+goos, "GOARCH="+goarch, "CGO_ENABLED=0")+ if b, err := cmd.CombinedOutput(); err != nil {+ t.Skipf("cannot cross-build %s/%s here: %v: %s", goos, goarch, err, b)+ }+ return out+}++func TestNativeArchIdentifiesEveryReleaseTarget(t *testing.T) {+ for _, tc := range []struct{ goos, goarch string }{+ {"darwin", "arm64"},+ {"darwin", "amd64"},+ {"linux", "amd64"},+ {"linux", "arm64"},+ {"windows", "amd64"},+ {"windows", "arm64"},+ } {+ t.Run(tc.goos+"_"+tc.goarch, func(t *testing.T) {+ got, ok := nativeArch(buildFor(t, tc.goos, tc.goarch))+ if !ok || got != tc.goarch {+ t.Fatalf("nativeArch = (%q, %v), want (%q, true)", got, ok, tc.goarch)+ }+ })+ }+}++// The x86_64 Python that reached Apple Silicon users survived every setup and+// update because provisioning only checked that the file existed.+func TestNativeBinRejectsForeignArch(t *testing.T) {+ foreign := "amd64"+ if runtime.GOARCH == "amd64" {+ foreign = "arm64"+ }+ if nativeBin(buildFor(t, runtime.GOOS, foreign)) {+ t.Fatalf("nativeBin accepted a %s binary on %s", foreign, runtime.GOARCH)+ }+ if !nativeBin(buildFor(t, runtime.GOOS, runtime.GOARCH)) {+ t.Fatal("nativeBin rejected a native binary")+ }+}++// Scripts and universal binaries have no single arch to compare, and treating+// "cannot tell" as a mismatch would wipe and re-download a working runtime.+func TestNativeBinAllowsUnidentifiableFiles(t *testing.T) {+ p := filepath.Join(t.TempDir(), "script")+ if err := os.WriteFile(p, []byte("#!/bin/sh\necho hi\n"), 0o755); err != nil {+ t.Fatal(err)+ }+ if !nativeBin(p) {+ t.Fatal("nativeBin should accept a format it cannot identify")+ }+}++func TestNativeBinRejectsMissingFile(t *testing.T) {+ if nativeBin(filepath.Join(t.TempDir(), "absent")) {+ t.Fatal("nativeBin accepted a file that does not exist")+ }+}diff --git a/cli/internal/provision/provision.go b/cli/internal/provision/provision.goindex ba1aa8e..262e6c2 100644--- a/cli/internal/provision/provision.go+++ b/cli/internal/provision/provision.go@@ -217,13 +217,32 @@ func downloadOnce(url, tmp, label string) (bool, error) {// zip-slip defense, since the path guard alone only validates the link's own// location, not where it points.func symlinkTargetInside(linkPath, linkname, root string) bool {- if filepath.IsAbs(linkname) {+ if rootedAnywhere(linkname) {return false}resolved := filepath.Clean(filepath.Join(filepath.Dir(linkPath), linkname))return strings.HasPrefix(resolved+string(os.PathSeparator), root)}+// rootedAnywhere reports whether p is rooted on any host, not merely this one.+// Archive members carry POSIX paths while filepath.IsAbs answers for the running+// OS: on Windows it calls "/etc/passwd" relative, so a rooted symlink target+// would pass the guard and then resolve against the drive root.+func rootedAnywhere(p string) bool {+ if p == "" {+ return false+ }+ if filepath.IsAbs(p) || p[0] == '/' || p[0] == '\\' {+ return true+ }+ // "C:/x", and drive-relative "C:x", both leave the destination on Windows.+ if len(p) >= 2 && p[1] == ':' {+ c := p[0] | 0x20+ return c >= 'a' && c <= 'z'+ }+ return false+}+// ParseChecksums parses sha256sum-style "<hex> <name>" lines into a name->hash// map, keyed by basename so it matches the asset filenames consumers request.func ParseChecksums(data []byte) map[string]string {@@ -259,17 +278,14 @@ type ffArchive struct {Bins []string}-// Static ffmpeg sources are not yet pinned by checksum (upstream "latest" URLs);-// they get our own pinned builds once podcli hosts releases.+// Static ffmpeg sources are not yet pinned by checksum (upstream "latest" URLs).+// darwin/arm64 is absent on purpose: evermeet.cx only builds x86_64, so Apple+// Silicon is served by our own release asset (see releaseFFmpeg).var ffmpegSpecs = map[string][]ffArchive{"darwin/amd64": {{URL: "https://evermeet.cx/ffmpeg/getrelease/ffmpeg/zip", Bins: []string{"ffmpeg"}},{URL: "https://evermeet.cx/ffmpeg/getrelease/ffprobe/zip", Bins: []string{"ffprobe"}},},- "darwin/arm64": {- {URL: "https://evermeet.cx/ffmpeg/getrelease/ffmpeg/zip", Bins: []string{"ffmpeg"}},- {URL: "https://evermeet.cx/ffmpeg/getrelease/ffprobe/zip", Bins: []string{"ffprobe"}},- },"linux/amd64": {{URL: "https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz", Bins: []string{"ffmpeg", "ffprobe"}},},@@ -434,9 +450,10 @@ func verifyReleaseAsset(assets map[string]string, assetName, path string) errorfunc EnsureWhisperCpp() (string, error) {bin := WhisperCLIBin()- if have(bin) {+ if nativeBin(bin) {return bin, nil}+ os.Remove(bin)name := fmt.Sprintf("whisper-cli-%s-%s%s", runtime.GOOS, runtime.GOARCH, paths.ExeSuffix())assets, err := latestReleaseAssets()if err != nil {@@ -465,19 +482,26 @@ func FFmpegBin() string {return filepath.Join(paths.RuntimeDir(), "ffmpeg", "ffmpeg"+paths.ExeSuffix())}+func FFprobeBin() string {+ return filepath.Join(paths.RuntimeDir(), "ffmpeg", "ffprobe"+paths.ExeSuffix())+}+func EnsureFFmpeg() (string, error) {bin := FFmpegBin()- if have(bin) {+ if nativeBin(bin) && nativeBin(FFprobeBin()) {return bin, nil}- specs, ok := ffmpegSpecs[runtime.GOOS+"/"+runtime.GOARCH]- if !ok {- return "", fmt.Errorf("no ffmpeg build for %s/%s", runtime.GOOS, runtime.GOARCH)- }dir := filepath.Join(paths.RuntimeDir(), "ffmpeg")if err := os.MkdirAll(dir, 0o755); err != nil {return "", err}+ if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {+ return bin, releaseFFmpeg()+ }+ specs, ok := ffmpegSpecs[runtime.GOOS+"/"+runtime.GOARCH]+ if !ok {+ return "", fmt.Errorf("no ffmpeg build for %s/%s", runtime.GOOS, runtime.GOARCH)+ }for _, a := range specs {sum := sha256.Sum256([]byte(a.URL))archive := filepath.Join(os.TempDir(), "podcli-ff-"+hex.EncodeToString(sum[:8]))@@ -496,6 +520,34 @@ func EnsureFFmpeg() (string, error) {return bin, nil}+// Apple Silicon builds ship with the release, checksum-verified like whisper-cli.+// No upstream publishes an arm64 macOS static, so ffmpeg used to arrive as an+// x86_64 binary that ran under Rosetta at roughly a third of native encode speed.+func releaseFFmpeg() error {+ assets, err := latestReleaseAssets()+ if err != nil {+ return err+ }+ for tool, bin := range map[string]string{"ffmpeg": FFmpegBin(), "ffprobe": FFprobeBin()} {+ name := fmt.Sprintf("%s-%s-%s", tool, runtime.GOOS, runtime.GOARCH)+ url, ok := assets[name]+ if !ok {+ return fmt.Errorf("asset %s not in latest release", name)+ }+ os.Remove(bin)+ if err := fetch(url, bin, tool); err != nil {+ return err+ }+ if err := verifyReleaseAsset(assets, name, bin); err != nil {+ return err+ }+ if err := os.Chmod(bin, 0o755); err != nil {+ return fmt.Errorf("chmod %s: %w", bin, err)+ }+ }+ return nil+}+func extractBins(archive string, bins []string, dest string) error {f, err := os.Open(archive)if err != nil {@@ -611,7 +663,7 @@ func PythonBin() string {}func pythonHealthy(bin string) bool {- if !have(bin) {+ if !nativeBin(bin) {return false}root := pythonRoot(bin)diff --git a/cli/internal/provision/security_test.go b/cli/internal/provision/security_test.goindex 7a747c1..202e5cb 100644--- a/cli/internal/provision/security_test.go+++ b/cli/internal/provision/security_test.go@@ -40,6 +40,12 @@ func TestSymlinkTargetInside(t *testing.T) {{"escape via dotdot", "/tmp/dest/link", "../../etc/passwd", false},{"absolute", "/tmp/dest/link", "/etc/passwd", false},{"deep escape", "/tmp/dest/a/b/link", "../../../outside", false},+ // Rooted targets must be refused on every host, not just the ones where+ // filepath.IsAbs happens to recognise them. On Windows it calls+ // "/etc/passwd" relative, which used to let these through.+ {"backslash rooted", "/tmp/dest/link", `\Windows\System32`, false},+ {"drive absolute", "/tmp/dest/link", "C:/Windows/System32", false},+ {"drive relative", "/tmp/dest/link", "C:evil", false},}for _, c := range cases {if got := symlinkTargetInside(c.linkPath, c.linkname, root); got != c.ok {