142 Commits

Author SHA1 Message Date
Ethanfel a67e189aa0 fix: mpv loadfile index arg, cache polling, and sidebar CSS
- Pass integer index (-1) to mpv loadfile command for newer mpv versions
- Poll /api/cache/status instead of streaming endpoints to avoid
  downloading video bodies during readiness checks
- Cancel previous polling when selecting a new file
- Fix sidebar flex-shrink and file name text overflow

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-17 08:17:23 +02:00
Ethanfel 2b6c56cd15 fix: add CORS middleware to server for Tauri webview requests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 20:49:53 +02:00
Ethanfel 0f6082061f feat: add folder navigation to file browser
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 20:25:03 +02:00
Ethanfel 9662b815db feat: add server URL input to profile bar
Type URL + Enter or click Set. Persisted via localStorage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 20:15:42 +02:00
Ethanfel 9776b83ac5 fix: client bug fixes from review
- FileBrowser: reload hidden files when profile changes
- WebSocket: wrap JSON.parse in try-catch
- WebSocket: exponential backoff on reconnect (2s -> 30s max)
- WebSocket: clean up connection on destroy

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 20:09:21 +02:00
Ethanfel 39f873bec2 fix: server bug fixes from review
- DB: add threading.Lock on all write methods and multi-step reads
- export.py: check audio extraction return code, raise on failure
- routes/export: counter race condition fix with _counter_lock
- routes/export: delete validation accepts EXPORT_DIR_suffix siblings
- routes/export: evict old finished jobs to prevent unbounded growth
- client plan: fix 10 bugs (mpv IPC, encodePath, input_path sep, etc.)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 19:53:38 +02:00
Ethanfel 409eb82e5c feat: configure Linux packaging (deb + AppImage)
Renamed to 8-cut, 1200x800 window, .deb builds at 3.9MB.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 19:52:40 +02:00
Ethanfel 297aafa51c feat: add settings persistence via localStorage
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 19:50:01 +02:00
Ethanfel b4cf972d59 feat: wire up main app layout with all components
Sidebar file browser, canvas timeline, transport bar, export panel,
profile bar, keyboard shortcuts, quality-reactive stream reload.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 19:48:54 +02:00
Ethanfel 5cc1e52e75 feat: add profile bar component
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 19:10:32 +02:00
Ethanfel 6bf0b0ae99 feat: add export panel component
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 19:10:03 +02:00
Ethanfel b6fbda01dd feat: add canvas-based timeline component
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 19:07:21 +02:00
Ethanfel 51d41f0a56 feat: add file browser component
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 19:06:41 +02:00
Ethanfel 16bd1a9ae0 feat: add mpv TypeScript bridge
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 18:46:35 +02:00
Ethanfel 2036c49b52 feat: add mpv sidecar IPC and Tauri commands
Persistent BufReader + request_id matching for correct event handling.
Audio-file passed during loadfile for frame-accurate sync.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 18:46:01 +02:00
Ethanfel b12758c53c feat: add WebSocket client for export progress
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 18:41:12 +02:00
Ethanfel 3d484952c2 feat: add Svelte stores for app state
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 18:40:43 +02:00
Ethanfel 12dae93671 feat: add server API client module
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 18:34:23 +02:00
Ethanfel 1e65fd6b0f feat: scaffold Tauri + Svelte client
SvelteKit in SPA mode with Tauri v2. Builds and produces .deb bundle.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 18:33:45 +02:00
Ethanfel f7756320e5 docs: add Tauri + Svelte client implementation plan
15-task plan covering Rust install, Tauri scaffold, mpv sidecar,
API client, stores, UI components, keyboard shortcuts, and packaging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 17:02:56 +02:00
Ethanfel cd0331d4ce docs: add Tauri + Svelte client design
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 16:57:29 +02:00
Ethanfel 38c6174f83 ci: disable auto Docker build, manual dispatch only
Build locally and push to ghcr.io instead — nvidia/cuda base is too
large for GitHub runners.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 15:23:32 +02:00
Ethanfel 5b22bceed2 ci: add GitHub Actions workflow to build Docker image
Docker Image / build (push) Has been cancelled
Triggers on pushes to server branch or version tags when
core/, server/, or Docker files change. Pushes to ghcr.io.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 14:48:22 +02:00
Ethanfel 80f21915e3 feat: switch to nvidia/cuda base image for NVENC hw encoding
- Base: nvidia/cuda:12.6.3-runtime-ubuntu24.04
- ffmpeg from apt has NVENC support when GPU runtime is available
- docker-compose reserves all GPUs via deploy.resources

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 14:47:19 +02:00
Ethanfel b09ba3fa9e fix: third-pass review bugs
- Switch DELETE /export to query param (path param strips leading /)
- Add CropKeyframe Pydantic model for typed keyframe validation
- Convert keyframes to tuples before passing to apply_keyframes_to_jobs
- Remove dead QFrame import from main.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 14:20:20 +02:00
Ethanfel 5b7a55a05d fix: second-pass review bugs in server and core
- ExportRunner: stop batch on first error (was continuing, overwriting
  error status with done)
- Export route: validate input_path against MEDIA_DIRS
- Export route: validate encoder, portrait_ratio, folder_suffix, name
- Export route: fix format check for WebP sequence
- Export route: add _ separator in folder_suffix (match GUI)
- Export route: use realpath consistently in delete endpoint
- Export route: drop runner ref on completion (prevent memory leak)
- ProcessedDB: use cursor-level row_factory (thread-safe)
- WebSocket: catch all exceptions in connect, cleanup in finally
- Dockerfile: use uvicorn[standard] for websockets support

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 14:10:27 +02:00
Ethanfel 2200da491f fix: address review bugs in server implementation
- Fix keyframe 6-tuple → 4-tuple mismatch crashing ExportRunner
- Fix ws.broadcast() using wrong event loop from background threads
- Fix export counter hardcoded to 1, now auto-increments
- Add path traversal protection to file/stream/delete endpoints
- Use proper HTTP error codes (was returning 200 for errors)
- Add thread safety to WebSocket connection list
- Record exports to DB so markers appear
- Move WS endpoint to /ws/export (was /api/ws/export)
- Prune dead threads from cache job tracker

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:55:25 +02:00
Ethanfel 3d6469c60c feat: add Dockerfile and docker-compose for server deployment
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:49:43 +02:00
Ethanfel 6a4ac8b8ed feat: add hidden files API endpoints
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:49:30 +02:00
Ethanfel 1f6906c946 feat: add export endpoint with WebSocket progress
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:49:16 +02:00
Ethanfel dfba88a601 feat: add markers/profiles/labels API endpoints
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:48:33 +02:00
Ethanfel e94c088df0 feat: add video streaming with transcode cache and audio extraction
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:48:06 +02:00
Ethanfel 9569103edd feat: add FastAPI app with file listing endpoint
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:47:23 +02:00
Ethanfel 079afeee7c feat: create server/config with env var settings and quality presets
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:44:31 +02:00
Ethanfel fbbfa6fdce refactor: import shared logic from core/ instead of inline definitions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:43:44 +02:00
Ethanfel 56920a5247 feat: create core/tracking module with YOLO subject tracking
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:39:52 +02:00
Ethanfel 08c1dd8b33 feat: create core/export module with ExportRunner
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:39:24 +02:00
Ethanfel 2b63ad1857 feat: create core/annotations module
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:38:47 +02:00
Ethanfel 72f6a4e8f5 feat: create core/db module with ProcessedDB
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:38:20 +02:00
Ethanfel 799a2ab353 feat: create core/ffmpeg module with ffmpeg helpers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:34:59 +02:00
Ethanfel 066f4431ba feat: create core/paths module with shared path helpers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:34:17 +02:00
Ethanfel 97f9ef7073 fix: correct bugs in server API implementation plan
- Fix line range 38→36 for _frozen_path extraction
- Clarify line ranges for ffmpeg vs annotation functions
- Remove unused imports (_frozen_path, build_annotation_json_path) from main.py import list
- Add step to clean up dead stdlib imports (re, json, sqlite3, tempfile, datetime)
- Add explicit stub router code for stream, markers, export, hidden
- Add server/__init__.py and server/routes/__init__.py content
- Add _DBWorker and FrameGrabber to "keep in main.py" list
- Note optional tracking deps in Dockerfile

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:33:36 +02:00
Ethanfel 592e40c1a6 docs: add server API implementation plan
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:24:03 +02:00
Ethanfel 73dd7a1569 docs: add server API design for remote editing via Tauri client
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:20:13 +02:00
Ethanfel 7abf0b4d4c feat: autoclip, play/pause improvements, number key exports, focus fix
- Autoclip (A): adjusts clip count to fit current pause position
- Pause no longer resets playback position — stays where paused
- Play resumes from pause point instead of restarting
- Spread/clips changes update loop end without restarting playback
- Number keys 1-9 export to subprofiles
- Click-away clears focus from spinboxes so hotkeys work again
- Lock mode: double-click marker jumps cursor to end of clip span

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:19:21 +02:00
Ethanfel 9e5bd4a8ec feat: add subprofiles, live play loop update, fix lock mode scrub
- Subprofiles: lightweight export variants that append a suffix to the
  export folder (e.g. _soft, _intense). Each gets its own export button
  in the transport row. Managed via "+" menu, persisted in QSettings.
- Play loop now updates immediately when spread/clips spinboxes change.
- Lock mode: ignore stale mpv position updates while user is dragging
  to prevent the play position from jumping back.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 23:58:26 +02:00
Ethanfel c5dd2d00a0 fix: use noarchive mode and enable console to debug PYZ TOC error
Build & Release / windows (push) Has been cancelled
Build & Release / macos (push) Has been cancelled
Build & Release / release (push) Has been cancelled
Bypasses PYZ archive entirely — modules stored as individual .pyc files.
Console enabled temporarily to capture error output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 23:12:58 +02:00
Ethanfel 34d8ad1dc7 feat: add Windows setup script and launcher for running from source
- setup-windows.ps1: downloads libmpv DLL and ffmpeg, installs pip deps
- 8cut.bat: double-click launcher
- main.py: add_dll_directory for libmpv next to script (not just frozen)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 23:08:17 +02:00
Ethanfel 46bd617f0a fix: disable UPX compression to prevent PYZ archive corruption
Build & Release / windows (push) Has been cancelled
Build & Release / macos (push) Has been cancelled
Build & Release / release (push) Has been cancelled
UPX can corrupt Python bytecode in PyInstaller bundles, causing
"PYZ archive entry not found in the TOC" on Windows.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 23:06:30 +02:00
Ethanfel e8ecfc0525 ci: publish release automatically, re-enable macOS build
Build & Release / windows (push) Has been cancelled
Build & Release / macos (push) Has been cancelled
Build & Release / release (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 22:59:29 +02:00
Ethanfel 198ec68382 ci: temporarily disable macOS job while debugging Windows build
Build & Release / windows (push) Has been cancelled
Build & Release / macos (push) Has been cancelled
Build & Release / release (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 22:49:08 +02:00
Ethanfel 920f724dbd fix: find libmpv asset by name pattern instead of constructing URL
Build & Release / windows (push) Has been cancelled
Build & Release / macos (push) Has been cancelled
Build & Release / release (push) Has been cancelled
Asset filenames include a git hash that can't be predicted from the tag
alone. Use the API assets list to find the correct download URL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 22:48:08 +02:00
Ethanfel 94ea4c63ca fix: use GitHub API to fetch latest libmpv tag instead of redirect
Build & Release / windows (push) Has been cancelled
Build & Release / macos (push) Has been cancelled
Build & Release / release (push) Has been cancelled
Invoke-WebRequest fails on 302 redirects in newer PowerShell.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 22:45:44 +02:00
Ethanfel 653e4a5e13 refactor: split Windows and macOS into separate jobs
Build & Release / windows (push) Has been cancelled
Build & Release / macos (push) Has been cancelled
Build & Release / release (push) Has been cancelled
Release is created if at least one platform succeeds, so a failure
on one doesn't block the other.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 22:44:13 +02:00
Ethanfel cd50b3ae0c fix: quote PowerShell path interpolation in ffmpeg copy step
Build & Release / build (8cut-macos-arm64, macos-latest) (push) Has been cancelled
Build & Release / build (8cut-windows, windows-latest) (push) Has been cancelled
Build & Release / release (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 22:43:03 +02:00
Ethanfel 10b77e79f7 fix: drop macos-13 runner (no longer available)
Build & Release / build (8cut-macos-arm64, macos-latest) (push) Has been cancelled
Build & Release / build (8cut-windows, windows-latest) (push) Has been cancelled
Build & Release / release (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 22:42:36 +02:00
Ethanfel 5b4e4bf818 feat: add PyInstaller spec and GitHub Actions release workflow
Build & Release / build (8cut-macos-arm64, macos-latest) (push) Has been cancelled
Build & Release / build (8cut-macos-x86_64, macos-13) (push) Has been cancelled
Build & Release / build (8cut-windows, windows-latest) (push) Has been cancelled
Build & Release / release (push) Has been cancelled
Enables cross-platform builds for Windows and macOS. Adds _bin() helper
to resolve bundled ffmpeg in frozen builds, and configures ctypes library
path for bundled libmpv.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 22:40:44 +02:00
Ethanfel bd4e97c45a fix: lock mode seek falls back to cursor instead of jumping to start
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 19:15:01 +02:00
Ethanfel 1aeaad7f6d fix: skip keyframe creation at frame 0 where base state applies
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 16:56:48 +02:00
Ethanfel 874632dffa fix: keep export complete message visible until next action
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 16:52:37 +02:00
Ethanfel 86055f2072 fix: defer preview follow so geometry is up-to-date after main window move
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 16:51:27 +02:00
Ethanfel 5fddb06354 fix: add right margin to panel, make Hide exported a QPushButton
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 16:48:51 +02:00
Ethanfel e60263548d feat: move status messages to inline label on settings row
Replace the bottom status bar with a right-aligned label on the
settings row, saving vertical space. Add "Export complete" message
when a batch finishes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 16:45:10 +02:00
Ethanfel 86f447f3d6 feat: add Show Hidden button to reveal and unhide playlist files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 16:39:22 +02:00
Ethanfel 1d5b8023a2 feat: auto-create/remove keyframes when toggling random crop in lock mode
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 16:29:11 +02:00
Ethanfel cb4392125d fix: scrub preview fallback before first keyframe + document overwrite behavior
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 16:08:35 +02:00
Ethanfel 328c800d60 feat: apply keyframe crop modes in overwrite exports too
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 16:05:20 +02:00
Ethanfel 7a35e8268b feat: preview effective keyframe crop state during lock-mode scrub
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 16:05:08 +02:00
Ethanfel 465894af51 feat: color-code keyframe diamonds by crop mode
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 16:04:53 +02:00
Ethanfel 1004bd0a28 feat: rewrite export to use per-keyframe crop modes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 15:58:01 +02:00
Ethanfel 279aee14cb feat: add apply_keyframes_to_jobs helper
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 15:57:27 +02:00
Ethanfel 4f15f77175 feat: snapshot ratio and random flags into crop keyframes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 15:52:25 +02:00
Ethanfel 17e42c44b3 refactor: widen keyframe tuple to carry ratio and random flags
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 15:52:04 +02:00
Ethanfel 8e8c8b9774 feat: add resolve_keyframe helper to extract sorted-keyframe lookup
Adds a pure function that returns the latest keyframe at or before a
given time (with tolerance), replacing the inline lookup pattern that
appears multiple times in main.py. Includes 6 tests covering empty
list, before-first, exact match, between, after-last, and tolerance.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 15:48:00 +02:00
Ethanfel b9e9fa927e chore: add .worktrees/ to .gitignore 2026-04-14 15:45:26 +02:00
Ethanfel 5916b498b1 docs: add keyframe crop modes implementation plan
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 15:30:46 +02:00
Ethanfel bda423e8b5 docs: add keyframe crop modes design
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 15:28:40 +02:00
Ethanfel 7b569dd248 docs: fix README to match current codebase
Remove fuzzy matching references (feature was removed), correct
test count (54 → 46), clarify that category is only saved to the
database not dataset.json, and add missing G and ?/F1 shortcuts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 12:58:53 +02:00
Ethanfel 3a2fd3d50b docs: add segment diagram SVG to README overview
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 12:36:14 +02:00
Ethanfel cfc0cb2f09 feat: multi-select in playlist for batch hide/remove
Extended selection mode (Ctrl+click, Shift+click) enabled. Right-click
context menu adapts to selection count — hide or remove multiple files
at once. Single click without modifiers still loads the file.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 09:09:42 +02:00
Ethanfel d87b3c6da5 fix: disengage lock and clear keyframes when switching clips
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 08:53:33 +02:00
Ethanfel 39e7b19bc5 fix: rewrite playlist to never use hidden items, eliminating scroll bugs
Instead of hiding QListWidget items (which causes Qt to miscalculate
scroll position), the playlist now rebuilds its contents from scratch
whenever visibility changes. Only visible items exist in the widget.

- _rebuild() clears and repopulates from _paths filtered by visibility
- mark_done/unmark_done update in-place for visible items
- set_hidden_basenames and set_hide_exported trigger _rebuild
- Removes _LockedScrollBar, all scroll hacks, and workarounds

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 00:09:07 +02:00
Ethanfel ab5c8ae3db fix: scroll playlist to top after session resume
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 00:05:56 +02:00
Ethanfel dcd4a6aace fix: locked scrollbar snaps to top instead of drifting
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 00:05:08 +02:00
Ethanfel 96d4dd8d89 fix: replace scrollTo override with locked scrollbar to block all scroll
_LockedScrollBar subclasses QScrollBar and blocks setValue when locked.
This catches ALL scroll sources — Qt layout, auto-scroll, item changes —
not just scrollTo. Locked during setCurrentRow, visibility changes,
playlist checks, and video load (200ms after load to catch late events).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 00:00:58 +02:00
Ethanfel a6b91d9d3f fix: crop keyframes and position apply to random portrait/square exports
Keyframes were skipped when ratio was None (random mode), and random
crop was overwriting the resolved center with base_center. Now
keyframes resolve the center for all jobs first, then random crop
assigns the ratio while preserving the per-job center.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 23:55:06 +02:00
Ethanfel 12b06e8144 feat: cancel button to abort running exports
ExportWorker now uses Popen instead of subprocess.run so running
ffmpeg processes can be killed on cancel. Cancel button appears
between Export and worker count spinner, enabled during export.
Clips already finished before cancel are kept in the DB.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 23:49:44 +02:00
Ethanfel 4c3b3fb2db fix: override scrollTo to block Qt auto-scroll during playlist operations
Replace timer hacks and scrollbar save/restore with a proper fix:
PlaylistWidget.scrollTo() is overridden to no-op when _scroll_locked
is set. Lock is held during setCurrentRow, visibility changes,
playlist checks, and video load — all operations where Qt's internal
auto-scroll was causing the list to jump.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 23:47:52 +02:00
Ethanfel 89d6feee47 fix: restore playlist scroll at 0/50/150ms to catch late layout events
mpv video surface resize triggers layout events across multiple event
loop cycles. A single deferred restore was too early.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 23:45:05 +02:00
Ethanfel 7051cc5b93 fix: defer playlist scroll restore to next event loop iteration
Qt processes layout changes asynchronously, so restoring the scrollbar
immediately after _after_load was too early. Use QTimer.singleShot(0)
to restore after Qt finishes processing pending layout events.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 23:44:03 +02:00
Ethanfel 7c776e24af fix: stash playlist scroll before video load, restore after
Video load triggers layout changes (buttons, crop bar, preview window)
that cause Qt to recalculate the playlist scrollbar position. Now saves
the scroll value in _load_file and restores it at the end of _after_load.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 23:42:55 +02:00
Ethanfel 04e78eb355 fix: remove scrollToItem that was overriding saved scroll position
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 23:41:19 +02:00
Ethanfel 97986d5138 fix: save/restore scrollbar position to prevent playlist scroll jumping
setCurrentRow, setHidden, and setText all trigger Qt internal scroll
recalculation. Now save scrollbar value before these operations and
restore it after, then use scrollToItem only to bring off-screen
selections into view.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 23:40:17 +02:00
Ethanfel 3c903c7188 feat: right-click keyframe diamond on timeline to delete it
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 17:11:32 +02:00
Ethanfel bef08be091 fix: crop keyframe in lock mode updates video overlay and preview lines
The lock-mode path was only updating the crop bar but not the video
overlay or random overlays. Now sets _crop_center and calls the
appropriate overlay update.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 17:10:02 +02:00
Ethanfel ccc94ccb5c fix: preview crop lines match main overlay colors
Portrait lines are red, square lines are blue — matching the video
overlay. Both shown simultaneously when both random options are on.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 17:07:07 +02:00
Ethanfel d031d6c285 fix: hide-exported checkbox state applied on session resume
_apply_playlist_filters now syncs _hide_exported from checkbox before
refreshing visibility, so exported files are hidden immediately on
startup without needing to toggle the checkbox.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 17:03:08 +02:00
Ethanfel 9696b94b0c fix: preview crop shows lines only (no dim), updates on random toggle
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 17:00:44 +02:00
Ethanfel 633e421a68 feat: show crop region overlay on end-frame preview
PreviewLabel widget replaces plain QLabel, draws dimmed areas outside
the crop window and blue border lines matching the crop bar position.
Updates live when portrait ratio or crop center changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:58:31 +02:00
Ethanfel a543c72ff5 fix: prevent scroll jumping by batching visibility and layout updates
- _apply_visibility wraps setHidden loop with setUpdatesEnabled and
  scrolls back to current item after
- _refresh_playlist_checks wraps mark_done/unmark_done loop similarly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:55:21 +02:00
Ethanfel 31772b898c fix: hidden files reappear on restart, scroll jumps on selection
- Centralize item visibility in _apply_visibility: hidden if
  profile-hidden OR (hide_exported AND done)
- mark_done/unmark_done no longer touch setHidden directly
- Session resume selects first visible item after filters applied
- add_files defers to _select_first_visible to skip hidden items

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:53:17 +02:00
Ethanfel 9b8d742fde fix: scroll to selected item to prevent list jumping on click
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:49:01 +02:00
Ethanfel 8392c022f6 feat: session resume, hide exported files, profile-based file hiding
- Resume last session: reload previous playlist files on startup
- Hide exported checkbox: filter out files with existing clips
- Profile-based hiding: right-click → "Hide in profile" persists via DB
- Playlist scrollbar fix: disable updates during batch add
- Drop event and profile switch use unified _apply_playlist_filters()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:47:44 +02:00
Ethanfel d4357f0da4 feat: cursor lock with crop keyframing, remove fuzzy filename matching
- Lock button (G key) freezes export cursor, timeline scrubs playback only
- In lock mode, clicking crop bar sets a keyframe at current playback time
- Orange diamonds on timeline show keyframe positions
- Export resolves per-clip crop center from nearest preceding keyframe
- Crop bar/overlay updates while scrubbing to preview effective crop
- Unlocking clears all keyframes
- Replace fuzzy filename matching with exact match to prevent marker bleed

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:34:49 +02:00
Ethanfel 2dcf9bc856 fix: preview window stays on top and raises with main window
- Add WindowStaysOnTopHint to keep preview above other windows
- Raise preview on main window activation (alt-tab, taskbar click)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 15:39:49 +02:00
Ethanfel 703874721b feat: YOLO subject tracking for per-clip crop centering, fix end-frame preview
- Track subject checkbox: auto-adjusts crop center per sub-clip using
  YOLOv8-nano detection on each start frame
- Detects target nearest to user's crop click, follows same class across clips
- Graceful fallback when ultralytics not installed or detection fails
- Fix end-frame preview not updating on clip/spread change (retry on busy grabber)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 15:12:17 +02:00
Ethanfel bd37938a4a fix: playlist shows clip count per file, export counter fills gaps after delete
- Playlist marks show [N] instead of ✓ to indicate how many clips exported
- Export counter scans from 1 to find first available slot instead of only advancing
- Refresh playlist checks and counter after marker/group deletion

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:37:59 +02:00
Ethanfel e28af38743 fix: compact playlist rows by replacing word wrap with middle ellipsis
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:16:24 +02:00
Ethanfel 039d383cf6 fix: VAAPI filter chain, overwrite duplicates, export cursor stash, shutdown guards
- VAAPI: hwdownload before CPU filters, skip HW setup for image sequences
- Delete old DB rows before overwrite re-insert to prevent duplicates
- Stash cursor at export time so async completion uses correct position
- Restore crop_center on marker click, fix falsy 0-value checks
- Remove stale pending marker on export error
- Guard double mpv termination in closeEvent
- SnapPreviewWindow recursion guard for dock/follow moves

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:07:20 +02:00
Ethanfel e283d96417 feat: HW encode toggle, workers control, GPU decode, verbose logging, UI polish
- Add HW encode checkbox (auto-detects NVENC/VAAPI/QSV/AMF/VideoToolbox),
  caps GPU workers to 3 to avoid concurrent session limits
- Add workers spinbox next to Export button to control parallel ffmpeg count
- Enable mpv hwdec=auto for GPU-accelerated video decoding during playback
- Add timestamped terminal logging for startup, file load, export, errors
- Reorder settings row: video settings (Resize, Portrait) then encoding
  (Format, HW, Clips, Spread, random crops)
- Fix filename label wrapping by using QSizePolicy.Ignored + no word wrap
- Alternating row colors in playlist for readability
- Snap-to-edge preview window: docks to main window edges, follows on move
- Fix SEGV on exit: explicit mpv shutdown in MainWindow.closeEvent before
  Qt tears down QObjects

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 12:56:00 +02:00
Ethanfel 1e99035393 feat: random square crop, shortcuts dialog, profile dropdown, video aspect fix
- Add "1 random square" checkbox (1:1 crop) alongside random portrait (9:16);
  both share the same ~1-per-3 quota when enabled together
- Multi-overlay system: portrait guides in red, square guides in blue, both
  visible simultaneously on the paused frame
- Replace editable profile QComboBox with non-editable dropdown + "New profile..."
  item via QInputDialog — fixes markers not updating on profile switch
- Refresh playlist checkmarks on profile switch (add/remove done marks)
- Add "?" button and ?/F1 shortcut to show keyboard shortcuts dialog
- Re-render video on widget resize to preserve aspect ratio
- Compute letterbox/pillarbox video rect for correct overlay + click mapping

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 12:10:39 +02:00
Ethanfel 0e38c5666e fix: reset overwrite/delete state on profile switch
Switching profiles now clears the overwrite path, button states, and
next-label so stale state from the old profile doesn't persist.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:22:20 +02:00
Ethanfel f9c5a42453 fix: make QComboBox dropdown arrow visible in dark theme
The previous border:none rule hid the dropdown indicator entirely,
making combos look like plain text fields.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:20:09 +02:00
Ethanfel f8b148f77d feat: profile support for independent marker sets
Each profile has its own set of timeline markers, so the same video
can be cut with different settings (e.g. landscape vs portrait) without
markers interfering. Profile selector in the top bar, persisted in
QSettings, stored per-row in the DB.

- Add `profile` column to ProcessedDB schema (migrates existing rows
  to 'default')
- Scope find_similar, get_markers, _get_markers_for by profile
- Add get_profiles() for populating the combo dropdown
- Thread profile through _DBWorker, _after_load, _refresh_markers,
  _on_clip_done, dropEvent, _on_open_files
- Editable profile QComboBox in top bar, refreshed after each export
- 5 new tests for profile isolation and backward compatibility (54 total)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:08:50 +02:00
Ethanfel 462af36bce docs: replace SELVA references with foley
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 03:01:38 +02:00
Ethanfel ae15f9ef32 docs: add social preview SVG/PNG and logo PNG
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 03:00:45 +02:00
Ethanfel 2ef387d87b docs: update README and add SVG logo
- Add timeline-style SVG banner with markers, playhead, and branding
- Rewrite README to reflect current features (batch export, SELVA
  annotation, group delete/overwrite, playlist, shortcuts)
- Remove outdated mask generation references
- Update test count to 49

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 02:58:47 +02:00
Ethanfel bcdda9c783 fix: UI audit — dark theme styling, group delete/overwrite, layout cleanup
- Style QComboBox/QSpinBox/QDoubleSpinBox/QCheckBox in dark theme
- Delete and overwrite now operate on the full clip group, not just one sub-clip
- Add get_group/delete_group to ProcessedDB with tests
- Restructure control rows: transport+actions / annotation+path / encoding
- Add "Open Files" button to queue panel (replaces drag-drop-only)
- Playlist right-click to remove items
- Compact time display (1:23.4 / 5:00.0), window title shows filename
- Short side: QLineEdit → QSpinBox with validation
- Tooltips with keyboard shortcuts on all interactive widgets
- Fix arrow hint direction, remove stale mask comment

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 02:56:26 +02:00
Ethanfel e2b4f9bf8d remove: mask generation, venv setup, and settings dialog
Dead code — masking is handled externally via ComfyUI. Removes
SetupWorker, MaskWorker, SettingsDialog, build_mask_output_dir,
the mask UI row, Settings button, and associated test cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 15:53:31 +02:00
Ethanfel bb6e3c623a fix: UX audit — shortcuts in text fields, delete confirmation, overwrite indicator
- Suppress global shortcuts (E/J/L/K/M/Space/P/arrows) when typing in
  text fields via ShortcutOverride event filter
- Add delete confirmation dialog before removing clips from disk + DB
- Export button turns red "Overwrite" when a marker is selected
- Reset stale overwrite/delete state when switching files
- Remove auto-advance after export; add N shortcut to advance manually
- Widen marker hit zones (±6→±10px click, ±4→±8px hover)
- Marker tooltip shows filename instead of full path

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 15:49:27 +02:00
Ethanfel 89e0478777 feat: parallel export, playback position, double-click markers, reset clips on video switch
- Parallelize batch ffmpeg exports with ThreadPoolExecutor
- Show playback progress as color fill in timeline selection region
- Single click moves playhead, double-click selects/deselects markers
- Reset clip count and spread to defaults when switching videos

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 11:42:40 +02:00
Ethanfel c287788d9e fix: marker click properly restores settings without cursor clear race
Emit marker_clicked before seek, and use a flag to prevent
_on_cursor_changed from immediately clearing the overwrite state
and settings that were just restored.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 11:01:29 +02:00
Ethanfel 5a5961ae21 fix: default short_side to 512 in DB schema
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 02:55:09 +02:00
Ethanfel c174d891fb fix: migrate DB schema with ALTER TABLE instead of dropping old data
Legacy records get new columns with sensible defaults and are preserved
as markers. No more data loss on schema upgrade.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 02:53:12 +02:00
Ethanfel 74e8656335 feat: save and restore all export config on marker click
DB now stores short_side, portrait_ratio, crop_center, format,
clip_count, and spread per export. Clicking a marker restores all
fields to the original export settings.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 02:52:02 +02:00
Ethanfel 206b95fc28 feat: restore label and category when clicking a marker
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 02:49:48 +02:00
Ethanfel f11b3e298e feat: group clips into subfolders (clip_001/, clip_002/, etc.)
Each batch export creates a subfolder named after the group (e.g.
clip_001/) containing all sub-clips and their audio files. Keeps
the top-level export folder clean.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 01:05:10 +02:00
Ethanfel 22e2ad27a0 fix: show one marker per batch, not one per sub-clip
Pending marker uses cursor position for the whole batch. DB markers
deduplicated by start_time since all sub-clips share the same cursor.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 00:41:41 +02:00
Ethanfel fee907f26f fix: raise clip count limit from 10 to 99
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 00:37:57 +02:00
Ethanfel 122f89547b feat: show crop bar with vertical lines when random portrait is enabled
When the random portrait checkbox is on and portrait dropdown is Off,
the crop bar appears and the video overlay shows 2 red vertical lines
(instead of filled red bands) indicating the 9:16 crop boundaries.
Clicking the crop bar or video adjusts the crop center position.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 00:30:49 +02:00
Ethanfel b6e7b660a8 fix: scale end-frame preview to 320x240
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 00:18:48 +02:00
Ethanfel 2304286147 fix: make end-frame preview a floating tool window
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:55:43 +02:00
Ethanfel abe9e6ee66 feat: end-frame preview panel showing last frame of clip spread
Small panel to the right of the video displays the frame at cursor +
clip_span. Updated with 300ms debounce on cursor move, spread/clip
count change, and file load. Uses ffmpeg to grab a single PNG frame
off the main thread.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:52:56 +02:00
Ethanfel 01961e9192 fix: move QSettings init before timeline setup
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:44:46 +02:00
Ethanfel d3e48f5276 fix: random portrait uses configured crop position, only randomizes which clip
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:43:16 +02:00
Ethanfel 0996670020 fix: random portrait always uses 9:16
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:40:47 +02:00
Ethanfel ffb99d3e66 fix: scale random portrait count — 1 per 3 clips (e.g. 2 for 6 clips)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:39:42 +02:00
Ethanfel 439bc85505 feat: random portrait — one clip per batch gets a random crop ratio + position
Checkbox '1 random portrait' in settings row. When checked, one random
clip in each batch receives a randomly chosen portrait ratio (9:16, 4:5,
or 1:1) with a random crop center. The rest use the global portrait
setting. Disabled for single-clip overwrite exports.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:38:56 +02:00
Ethanfel 13973dd53d fix: read clip_count/spread from settings before timeline init
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:34:03 +02:00
Ethanfel 9e07910df1 feat: make clip count configurable (1–10, default 3)
Clips spinbox in settings row alongside Spread. Preview span and export
batch size adjust dynamically.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:28:12 +02:00
Ethanfel 25250d6d8d fix: use lossless PCM audio in MP4 exports
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:26:02 +02:00
Ethanfel 93cee40b06 feat: export 3 overlapping 8s clips per press with configurable spread
Each export generates clip_NNN_0, clip_NNN_1, clip_NNN_2 offset by the
spread value (2–8s, default 3s). Preview plays the full span covered by
all three clips. Marker click still overwrites a single clip.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:22:41 +02:00
94 changed files with 16120 additions and 1064 deletions
+36
View File
@@ -0,0 +1,36 @@
name: Docker Image
on:
workflow_dispatch: # manual only — build locally and push to ghcr.io
permissions:
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/${{ github.repository }}-server
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha,prefix=
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
+115
View File
@@ -0,0 +1,115 @@
name: Build & Release
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
jobs:
# ── Windows ────────────────────────────────────────────────
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Python dependencies
run: pip install pyinstaller PyQt6 python-mpv
- name: Fetch ffmpeg
shell: pwsh
run: |
$ffUrl = "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
Invoke-WebRequest $ffUrl -OutFile ffmpeg.zip
Expand-Archive ffmpeg.zip -DestinationPath ffmpeg-tmp
$bin = Get-ChildItem -Path ffmpeg-tmp -Recurse -Filter ffmpeg.exe | Select-Object -First 1
Copy-Item "$($bin.DirectoryName)\ffmpeg.exe" .
Copy-Item "$($bin.DirectoryName)\ffprobe.exe" .
- name: Fetch libmpv
shell: pwsh
run: |
$release = Invoke-RestMethod "https://api.github.com/repos/shinchiro/mpv-winbuild-cmake/releases/latest"
$asset = $release.assets | Where-Object { $_.name -like "mpv-dev-x86_64-v3-*" } | Select-Object -First 1
Invoke-WebRequest $asset.browser_download_url -OutFile mpv-dev.7z
7z x mpv-dev.7z -ompv-dev
Copy-Item mpv-dev\libmpv-2.dll .
- name: Build with PyInstaller
run: pyinstaller 8cut.spec
- name: Package
shell: pwsh
run: Compress-Archive -Path dist\8cut\* -DestinationPath 8cut-windows.zip
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: 8cut-windows
path: 8cut-windows.zip
# ── macOS (Apple Silicon) ──────────────────────────────────
macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Python dependencies
run: pip install pyinstaller PyQt6 python-mpv
- name: Install native deps
run: |
brew install mpv ffmpeg
cp "$(brew --prefix mpv)/lib/libmpv.2.dylib" .
cp "$(brew --prefix ffmpeg)/bin/ffmpeg" .
cp "$(brew --prefix ffmpeg)/bin/ffprobe" .
- name: Build with PyInstaller
run: pyinstaller 8cut.spec
- name: Fix dylib rpaths
run: |
DYLIB="dist/8cut/libmpv.2.dylib"
if [ -f "$DYLIB" ]; then
install_name_tool -id @executable_path/libmpv.2.dylib "$DYLIB"
fi
- name: Package
run: |
cd dist
zip -r ../8cut-macos-arm64.zip 8cut.app
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: 8cut-macos-arm64
path: 8cut-macos-arm64.zip
# ── Create GitHub Release ──────────────────────────────────
release:
needs: [windows, macos]
if: ${{ always() && startsWith(github.ref, 'refs/tags/v') && (needs.windows.result == 'success' || needs.macos.result == 'success') }}
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create Release
uses: softprops/action-gh-release@v2
with:
draft: false
generate_release_notes: true
files: artifacts/**/*.zip
+3
View File
@@ -2,3 +2,6 @@ __pycache__/
*.pyc
*.pyo
.pytest_cache/
.worktrees/
client/node_modules/
client/src-tauri/target/
+3
View File
@@ -0,0 +1,3 @@
@echo off
cd /d "%~dp0"
python main.py %*
+142
View File
@@ -0,0 +1,142 @@
# -*- mode: python ; coding: utf-8 -*-
"""PyInstaller spec for 8-cut.
Usage:
pyinstaller 8cut.spec
Platform-specific notes:
Windows: place libmpv-2.dll, ffmpeg.exe, ffprobe.exe next to main.py
before building, or set FFMPEG_DIR / MPV_DIR env vars.
macOS: place libmpv.2.dylib, ffmpeg, ffprobe next to main.py
before building, or set FFMPEG_DIR / MPV_DIR env vars.
Linux: system libmpv and ffmpeg are used from PATH (not bundled).
"""
import os
import platform
import sys
from pathlib import Path
block_cipher = None
system = platform.system()
# ---------- paths ----------------------------------------------------------
base = Path(SPECPATH)
ffmpeg_dir = Path(os.environ.get("FFMPEG_DIR", base))
mpv_dir = Path(os.environ.get("MPV_DIR", base))
# ---------- data files -----------------------------------------------------
datas = []
# YOLOv8 model (optional — large, skip if missing)
yolo = base / "yolov8n.pt"
if yolo.exists():
datas.append((str(yolo), "."))
# ---------- native binaries ------------------------------------------------
binaries = []
if system == "Windows":
for name in ("libmpv-2.dll",):
p = mpv_dir / name
if p.exists():
binaries.append((str(p), "."))
for name in ("ffmpeg.exe", "ffprobe.exe"):
p = ffmpeg_dir / name
if p.exists():
binaries.append((str(p), "."))
elif system == "Darwin":
for name in ("libmpv.2.dylib", "libmpv.dylib"):
p = mpv_dir / name
if p.exists():
binaries.append((str(p), "."))
break
for name in ("ffmpeg", "ffprobe"):
p = ffmpeg_dir / name
if p.exists():
binaries.append((str(p), "."))
# ---------- analysis -------------------------------------------------------
a = Analysis(
[str(base / "main.py")],
pathex=[str(base)],
binaries=binaries,
datas=datas,
hiddenimports=[
"mpv",
"PyQt6.QtOpenGL",
"PyQt6.QtOpenGLWidgets",
],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[
# ultralytics is optional and huge — exclude from frozen build
"ultralytics",
"torch",
"torchvision",
"onnxruntime",
"opencv-python",
# test / dev
"pytest",
"hypothesis",
],
noarchive=True,
cipher=block_cipher,
)
pyz = PYZ(a.pure, cipher=block_cipher)
# ---------- executable -----------------------------------------------------
exe_kwargs = dict(
pyz=pyz,
a=a,
name="8cut",
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=True, # temporary: show errors on launch
)
if system == "Darwin":
exe_kwargs["icon"] = str(base / "assets" / "logo.png")
elif system == "Windows":
ico = base / "assets" / "logo.ico"
if ico.exists():
exe_kwargs["icon"] = str(ico)
exe = EXE(**exe_kwargs)
# ---------- collect --------------------------------------------------------
coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=False,
upx=False,
name="8cut",
)
# ---------- macOS .app bundle (only on Darwin) -----------------------------
if system == "Darwin":
app = BUNDLE(
coll,
name="8cut.app",
icon=str(base / "assets" / "logo.png"),
bundle_identifier="com.8cut.app",
info_plist={
"CFBundleDisplayName": "8cut",
"CFBundleShortVersionString": "1.0.0",
"NSHighResolutionCapable": True,
"LSMinimumSystemVersion": "11.0",
},
)
+13
View File
@@ -0,0 +1,13 @@
FROM nvidia/cuda:12.6.3-runtime-ubuntu24.04
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 python3-pip ffmpeg \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY core/ core/
COPY server/ server/
RUN pip install --no-cache-dir --break-system-packages fastapi uvicorn[standard]
EXPOSE 8000
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "8000"]
+88 -54
View File
@@ -1,32 +1,63 @@
# 8-cut
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/ethanfel/8-cut/blob/master/LICENSE)
<p align="center">
<img src="assets/logo.svg" alt="8-cut — 8-second clips for foley datasets" width="720">
</p>
**Source:** https://github.com/ethanfel/8-cut
<p align="center">
<a href="https://github.com/ethanfel/8-cut/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
</p>
A desktop tool for cutting 8-second clips from video files, designed for building [SELVA](https://github.com/google-deepmind/selva) datasets.
A desktop tool for cutting 8-second clips from video files, designed for building foley datasets.
## Overview
8-cut lets you scrub through a video, mark a cut point, and export a fixed 8-second clip with one keypress. It tracks every export in a local SQLite database so you can resume a session or switch between resolution variants of the same source without duplicating work.
8-cut lets you scrub through a video, mark a cut point, and export a batch of overlapping 8-second clips with one keypress. It tracks every export in a local SQLite database so you can resume a session without duplicating work.
All clips are exactly 8 seconds — this is a hard constraint of the SELVA format.
All clips are exactly 8 seconds — the standard length for foley sound datasets.
<p align="center">
<img src="assets/segment-diagram.svg" alt="Batch export diagram — 3 overlapping 8-second clips offset by a 3-second spread" width="720">
</p>
## Features
- **Frame-accurate scrubbing** — click or drag the timeline; arrow keys and J/K/L for frame-by-frame stepping
- **Keyboard shortcuts** — J/L step one frame, Shift+J/L step one second, Space/P play/pause, K pause and return to cursor, E export, M jump to next marker
- **Two export formats** — H.264/AAC MP4 or lossless WebP image sequence (frames + `.wav` audio extracted alongside)
- **Portrait crop** — crop to 9:16, 4:5, or 1:1 before export; adjustable horizontal crop position
- **Resize** — scale short side to a fixed pixel size (e.g. 256)
- **Export history** — timeline markers show previously exported clips; fuzzy filename matching detects resolution variants of the same file (e.g. `_2160p` vs `_1080p`)
- **Mask generation** — generate binary foreground masks per-frame using SAM2 (segmentation) or Depth Anything V2 (depth-based), via a bundled venv
- **Playlist** — drag-and-drop multiple files; duplicates are ignored
- **Frame-accurate scrubbing** — click or drag the timeline; arrow keys and J/L for frame-by-frame, Shift for 1-second steps
- **Batch export** — export multiple overlapping clips per cut point with configurable count and spread offset
- **Two export formats** — H.264 MP4 with lossless PCM audio, or WebP image sequence (frames + `.wav`)
- **Portrait crop** — crop to 9:16, 4:5, or 1:1 before export; click the video or crop bar to reposition
- **Random portrait** — optionally apply a random portrait crop to a subset of each batch
- **Resize** — scale short side to a fixed pixel size (e.g. 512)
- **Sound annotation** — label and category fields saved to the clip database; label also written to `dataset.json`
- **Export history** — timeline markers show previously exported clips; double-click to enter overwrite mode; right-click to delete
- **End-frame preview** — floating window shows the last frame of the selection region
- **Playlist** — drag-and-drop or use the Open Files button; right-click to remove items
- **Playback loop** — plays the exact selection region on loop so you can preview what will be exported
- **Group operations** — delete or overwrite acts on all sub-clips in a batch, not just one
- **Profiles** — switch between independent marker sets (e.g. "landscape" vs "portrait") for the same video
## Keyboard shortcuts
| Key | Action |
|-----|--------|
| `Left` / `J` | Step back 1 frame |
| `Right` / `L` | Step forward 1 frame |
| `Shift+Left` / `Shift+J` | Step back 1 second |
| `Shift+Right` / `Shift+L` | Step forward 1 second |
| `Space` / `P` | Toggle play/pause |
| `K` | Pause and snap to cursor |
| `E` | Export |
| `M` | Jump to next marker (wraps) |
| `N` | Next file in playlist |
| `G` | Toggle cursor lock |
| `?` / `F1` | Show keyboard shortcuts |
Shortcuts are suppressed when a text field has focus.
## Requirements
- Python 3.11+
- `ffmpeg` in `PATH`
- `ffmpeg` on `PATH`
- PyQt6
- python-mpv (requires libmpv)
@@ -34,15 +65,15 @@ All clips are exactly 8 seconds — this is a hard constraint of the SELVA forma
pip install -r requirements.txt
```
For mask generation tools, additional dependencies (PyTorch, transformers, segment-anything-2, opencv) are installed into `~/.8cut/venv/` via the Settings dialog.
### Platform notes
**Linux** — install libmpv via your package manager (`apt install libmpv-dev` / `pacman -S mpv`).
| Platform | libmpv |
|----------|--------|
| **Linux** | `apt install libmpv-dev` or `pacman -S mpv` |
| **macOS** | `brew install mpv` |
| **Windows** | Download `mpv-2.dll` from [mpv Windows builds](https://sourceforge.net/projects/mpv-player-windows/files/libmpv/) and place it in `PATH` or next to `main.py` |
**macOS** — install libmpv via Homebrew: `brew install mpv`.
**Windows**`python-mpv` requires `mpv-2.dll` in `PATH` or in the same directory as `main.py`. Download it from the [mpv Windows builds](https://sourceforge.net/projects/mpv-player-windows/files/libmpv/) page (pick the latest `mpv-dev-x86_64-*.7z`, extract `mpv-2.dll`). Also ensure `ffmpeg.exe` is in `PATH` (e.g. via [winget](https://winget.run/): `winget install ffmpeg`).
Windows also needs `ffmpeg.exe` on `PATH` (e.g. `winget install ffmpeg`).
## Usage
@@ -50,49 +81,52 @@ For mask generation tools, additional dependencies (PyTorch, transformers, segme
python main.py
```
Drop a video onto the playlist or use the file picker. Scrub to your cut point, set the output folder and clip name, then press **Export** (or `E`).
Drop videos onto the queue or click **+ Open Files**. Scrub to your cut point, then press **Export** (or `E`).
### Export formats
### Export layout
| Format | Output |
|--------|--------|
| MP4 | `<folder>/<name>_NNN.mp4` — H.264 video + AAC audio |
| WebP sequence | `<folder>/<name>_NNN/frame_%04d.webp` — lossless WebP frames + `<name>_NNN.wav` PCM audio |
### Keyboard shortcuts
| Key | Action |
|-----|--------|
| `←` / `J` | Step back 1 frame |
| `→` / `L` | Step forward 1 frame |
| `Shift+←` / `Shift+J` | Step back 1 second |
| `Shift+→` / `Shift+L` | Step forward 1 second |
| `Space` / `P` | Toggle play/pause |
| `K` | Pause and snap video to cursor |
| `E` | Export clip |
| `M` | Jump to next export marker (wraps) |
Arrow keys and J/K/L are ignored when a text field has focus.
### Mask generation tools
> **Warning:** The mask generation feature is untested and may not work reliably. For production use, consider [ComfyUI](https://github.com/comfyanonymous/ComfyUI) instead.
Two standalone scripts live in `tools/`. They are run by the app via a managed venv but can also be called directly:
Each export creates a group subfolder containing the overlapping sub-clips:
```
python tools/sam_masks.py --input clip.mp4 --output masks_dir/
python tools/depth_masks.py --input clip.mp4 --output masks_dir/
output/
clip_001/
clip_001_0.mp4 # starts at cursor
clip_001_1.mp4 # starts at cursor + spread
clip_001_2.mp4 # starts at cursor + 2 * spread
clip_002/
...
```
Both output one binary PNG per frame (`frame_0000.png`, …) where white = foreground.
With WebP sequence format, each sub-clip becomes a directory of frames plus a `.wav`:
- **SAM2** (`sam_masks.py`) — uses `facebook/sam2-hiera-large`; center-point prompt propagated across all frames
- **Depth Anything V2** (`depth_masks.py`) — uses `depth-anything/Depth-Anything-V2-Large-hf`; Otsu threshold on the depth map
```
output/
clip_001/
clip_001_0/
frame_0001.webp
frame_0002.webp
...
clip_001_0.wav
```
### Sound annotation
Set a **Label** (e.g. "dog barking") and **Category** (Human / Animal / Vehicle / Tool / Music / Nature / Sport / Other) before exporting. These are saved to:
- `dataset.json` in the export folder — one entry per clip with `path` and `label`
- The SQLite database — label and category, for recall when you revisit a marker
Labels persist between exports so you can cut many clips of the same class without retyping.
### Overwrite and delete
- **Double-click** a timeline marker to enter overwrite mode — the next export re-encodes all clips in that group to their original paths
- **Right-click** a marker to delete it from the database
- The **Delete** button removes all clips in a group from disk, database, and `dataset.json`
## Database
Export history is stored in `~/.8cut.db` (SQLite). The database records filename, start time, and output path for every clip. When you open a file, 8-cut checks whether a similar filename has been processed before (stripping resolution tags like `_2160p`, `_1080p`, codec tags, etc.) and pre-populates the timeline with existing markers.
Export history is stored in `~/.8cut.db` (SQLite). The database records filename, start time, output path, label, category, and all encoding settings for every clip. When you open a file, 8-cut matches the filename and pre-populates the timeline with existing markers.
## Testing
@@ -100,7 +134,7 @@ Export history is stored in `~/.8cut.db` (SQLite). The database records filename
pytest tests/ -v
```
38 unit tests covering path builders, ffmpeg command generation, time formatting, and the processed-clips database.
46 unit tests covering path builders, ffmpeg command generation, time formatting, database operations, group queries, profile isolation, and annotation handling.
## License
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

+95
View File
@@ -0,0 +1,95 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 200">
<defs>
<linearGradient id="timeline-bg" x1="0" y1="0" x2="1" y2="0">
<stop offset="0%" stop-color="#1e1e1e"/>
<stop offset="100%" stop-color="#2a2a2a"/>
</linearGradient>
<linearGradient id="selection" x1="0" y1="0" x2="1" y2="0">
<stop offset="0%" stop-color="#3c82dc" stop-opacity="0.6"/>
<stop offset="100%" stop-color="#3c82dc" stop-opacity="0.3"/>
</linearGradient>
<linearGradient id="eight-grad" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="#ffd230"/>
<stop offset="100%" stop-color="#e6a800"/>
</linearGradient>
</defs>
<!-- Background -->
<rect width="720" height="200" rx="12" fill="#161616"/>
<!-- Timeline track -->
<rect x="40" y="100" width="640" height="48" rx="4" fill="url(#timeline-bg)" stroke="#333" stroke-width="1"/>
<!-- Timeline lane -->
<rect x="40" y="112" width="640" height="24" rx="2" fill="#2a2a2a"/>
<!-- Selection region (8 seconds) -->
<rect x="240" y="100" width="140" height="48" rx="2" fill="url(#selection)"/>
<line x1="240" y1="100" x2="240" y2="148" stroke="#3c82dc" stroke-width="2" stroke-opacity="0.8"/>
<line x1="380" y1="100" x2="380" y2="148" stroke="#3c82dc" stroke-width="2" stroke-opacity="0.8"/>
<!-- Playhead -->
<line x1="240" y1="96" x2="240" y2="152" stroke="#ffd230" stroke-width="2"/>
<polygon points="234,96 246,96 240,104" fill="#ffd230"/>
<!-- Ruler ticks -->
<g stroke="#555" stroke-width="1">
<line x1="80" y1="100" x2="80" y2="108"/>
<line x1="120" y1="100" x2="120" y2="105"/>
<line x1="160" y1="100" x2="160" y2="108"/>
<line x1="200" y1="100" x2="200" y2="105"/>
<line x1="240" y1="100" x2="240" y2="108"/>
<line x1="280" y1="100" x2="280" y2="105"/>
<line x1="320" y1="100" x2="320" y2="108"/>
<line x1="360" y1="100" x2="360" y2="105"/>
<line x1="400" y1="100" x2="400" y2="108"/>
<line x1="440" y1="100" x2="440" y2="105"/>
<line x1="480" y1="100" x2="480" y2="108"/>
<line x1="520" y1="100" x2="520" y2="105"/>
<line x1="560" y1="100" x2="560" y2="108"/>
<line x1="600" y1="100" x2="600" y2="105"/>
<line x1="640" y1="100" x2="640" y2="108"/>
</g>
<!-- Export markers -->
<g>
<line x1="130" y1="100" x2="130" y2="148" stroke="#dc3c3c" stroke-width="2"/>
<rect x="130" y="102" width="14" height="12" rx="1" fill="#c83232"/>
<text x="137" y="112" font-family="sans-serif" font-size="9" fill="white" text-anchor="middle">1</text>
</g>
<g>
<line x1="390" y1="100" x2="390" y2="148" stroke="#dc3c3c" stroke-width="2"/>
<rect x="390" y="102" width="14" height="12" rx="1" fill="#c83232"/>
<text x="397" y="112" font-family="sans-serif" font-size="9" fill="white" text-anchor="middle">2</text>
</g>
<g>
<line x1="540" y1="100" x2="540" y2="148" stroke="#dc3c3c" stroke-width="2"/>
<rect x="540" y="102" width="14" height="12" rx="1" fill="#c83232"/>
<text x="547" y="112" font-family="sans-serif" font-size="9" fill="white" text-anchor="middle">3</text>
</g>
<!-- "8" numeral -->
<text x="100" y="72" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="72" font-weight="bold" fill="url(#eight-grad)">8</text>
<!-- "-cut" text -->
<text x="148" y="70" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="48" font-weight="300" fill="#cccccc">-cut</text>
<!-- Scissors icon near playhead -->
<g transform="translate(296, 82) scale(0.7)" fill="none" stroke="#999" stroke-width="2" stroke-linecap="round">
<circle cx="5" cy="5" r="4" />
<circle cx="5" cy="19" r="4" />
<line x1="9" y1="7" x2="20" y2="17"/>
<line x1="9" y1="17" x2="20" y2="7"/>
</g>
<!-- Tagline -->
<text x="400" y="72" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="14" fill="#777">8-second clips for foley datasets</text>
<!-- Duration label in selection -->
<text x="310" y="130" font-family="'Courier New', monospace" font-size="13" fill="#aad4ff" text-anchor="middle" opacity="0.9">8.0s</text>
<!-- Time labels -->
<text x="40" y="166" font-family="'Courier New', monospace" font-size="10" fill="#666">0:00</text>
<text x="230" y="166" font-family="'Courier New', monospace" font-size="10" fill="#e6a800">1:15</text>
<text x="640" y="166" font-family="'Courier New', monospace" font-size="10" fill="#666">5:00</text>
</svg>

After

Width:  |  Height:  |  Size: 4.4 KiB

+62
View File
@@ -0,0 +1,62 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 260">
<defs>
<marker id="al" markerWidth="6" markerHeight="4" refX="0" refY="2" orient="auto">
<path d="M6,0 L0,2 L6,4" fill="#777"/>
</marker>
<marker id="ar" markerWidth="6" markerHeight="4" refX="6" refY="2" orient="auto">
<path d="M0,0 L6,2 L0,4" fill="#777"/>
</marker>
<marker id="gl" markerWidth="6" markerHeight="4" refX="0" refY="2" orient="auto">
<path d="M6,0 L0,2 L6,4" fill="#e6a800"/>
</marker>
<marker id="gr" markerWidth="6" markerHeight="4" refX="6" refY="2" orient="auto">
<path d="M0,0 L6,2 L0,4" fill="#e6a800"/>
</marker>
</defs>
<!-- Background -->
<rect width="720" height="260" rx="12" fill="#161616"/>
<!-- Cursor / playhead -->
<text x="110" y="32" font-family="'Courier New', monospace" font-size="11" fill="#e6a800" text-anchor="middle">cursor</text>
<polygon points="104,38 116,38 110,46" fill="#ffd230"/>
<line x1="110" y1="46" x2="110" y2="195" stroke="#ffd230" stroke-width="1.5" stroke-dasharray="4,3"/>
<!-- Dashed guide lines at clip start offsets -->
<line x1="212" y1="56" x2="212" y2="195" stroke="#444" stroke-width="1" stroke-dasharray="2,4"/>
<line x1="314" y1="56" x2="314" y2="195" stroke="#444" stroke-width="1" stroke-dasharray="2,4"/>
<!-- Clip 0 -->
<text x="20" y="74" font-family="'Courier New', monospace" font-size="10" fill="#999">clip_001_0</text>
<rect x="110" y="56" width="272" height="28" rx="4" fill="#3c82dc" opacity="0.9"/>
<text x="246" y="74" font-family="'Courier New', monospace" font-size="11" fill="white" text-anchor="middle" opacity="0.9">8s</text>
<!-- Spread annotation 1 -->
<line x1="110" y1="88" x2="110" y2="104" stroke="#666" stroke-width="1"/>
<line x1="212" y1="88" x2="212" y2="104" stroke="#666" stroke-width="1"/>
<line x1="114" y1="96" x2="208" y2="96" stroke="#777" stroke-width="1" marker-start="url(#al)" marker-end="url(#ar)"/>
<text x="161" y="93" font-family="'Courier New', monospace" font-size="9" fill="#999" text-anchor="middle">spread 3s</text>
<!-- Clip 1 -->
<text x="20" y="126" font-family="'Courier New', monospace" font-size="10" fill="#999">clip_001_1</text>
<rect x="212" y="108" width="272" height="28" rx="4" fill="#5a9be6" opacity="0.85"/>
<text x="348" y="126" font-family="'Courier New', monospace" font-size="11" fill="white" text-anchor="middle" opacity="0.9">8s</text>
<!-- Spread annotation 2 -->
<line x1="212" y1="140" x2="212" y2="156" stroke="#666" stroke-width="1"/>
<line x1="314" y1="140" x2="314" y2="156" stroke="#666" stroke-width="1"/>
<line x1="216" y1="148" x2="310" y2="148" stroke="#777" stroke-width="1" marker-start="url(#al)" marker-end="url(#ar)"/>
<text x="263" y="145" font-family="'Courier New', monospace" font-size="9" fill="#999" text-anchor="middle">spread 3s</text>
<!-- Clip 2 -->
<text x="20" y="178" font-family="'Courier New', monospace" font-size="10" fill="#999">clip_001_2</text>
<rect x="314" y="160" width="272" height="28" rx="4" fill="#78b4f0" opacity="0.8"/>
<text x="450" y="178" font-family="'Courier New', monospace" font-size="11" fill="white" text-anchor="middle" opacity="0.9">8s</text>
<!-- Total span annotation -->
<line x1="110" y1="198" x2="110" y2="218" stroke="#e6a800" stroke-width="1"/>
<line x1="586" y1="198" x2="586" y2="218" stroke="#e6a800" stroke-width="1"/>
<line x1="114" y1="210" x2="582" y2="210" stroke="#e6a800" stroke-width="1" marker-start="url(#gl)" marker-end="url(#gr)"/>
<text x="348" y="235" font-family="'Courier New', monospace" font-size="12" fill="#e6a800" text-anchor="middle">total span: 14s</text>
<text x="348" y="250" font-family="'Courier New', monospace" font-size="10" fill="#666" text-anchor="middle">8 + (n&#x2212;1) &#xd7; spread</text>
</svg>

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

+132
View File
@@ -0,0 +1,132 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 640">
<defs>
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="#141414"/>
<stop offset="100%" stop-color="#1a1a1a"/>
</linearGradient>
<linearGradient id="tl-bg" x1="0" y1="0" x2="1" y2="0">
<stop offset="0%" stop-color="#1e1e1e"/>
<stop offset="100%" stop-color="#262626"/>
</linearGradient>
<linearGradient id="sel" x1="0" y1="0" x2="1" y2="0">
<stop offset="0%" stop-color="#3c82dc" stop-opacity="0.55"/>
<stop offset="100%" stop-color="#3c82dc" stop-opacity="0.2"/>
</linearGradient>
<linearGradient id="eight" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="#ffd230"/>
<stop offset="100%" stop-color="#d4a000"/>
</linearGradient>
<linearGradient id="glow" x1="0.5" y1="0" x2="0.5" y2="1">
<stop offset="0%" stop-color="#ffd230" stop-opacity="0.08"/>
<stop offset="100%" stop-color="#ffd230" stop-opacity="0"/>
</linearGradient>
</defs>
<!-- Background -->
<rect width="1280" height="640" fill="url(#bg)"/>
<!-- Subtle glow behind title -->
<ellipse cx="640" cy="200" rx="400" ry="140" fill="url(#glow)"/>
<!-- Title: "8" -->
<text x="440" y="250" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="180" font-weight="bold" fill="url(#eight)">8</text>
<!-- Title: "-cut" -->
<text x="560" y="244" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="110" font-weight="300" fill="#cccccc">-cut</text>
<!-- Tagline -->
<text x="640" y="310" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="26" fill="#777" text-anchor="middle">8-second video clips for foley datasets</text>
<!-- ===== Timeline ===== -->
<!-- Timeline track -->
<rect x="120" y="380" width="1040" height="72" rx="6" fill="url(#tl-bg)" stroke="#333" stroke-width="1"/>
<!-- Timeline lane -->
<rect x="120" y="398" width="1040" height="36" rx="3" fill="#2a2a2a"/>
<!-- Ruler ticks -->
<g stroke="#555" stroke-width="1">
<line x1="172" y1="380" x2="172" y2="392"/>
<line x1="224" y1="380" x2="224" y2="387"/>
<line x1="276" y1="380" x2="276" y2="392"/>
<line x1="328" y1="380" x2="328" y2="387"/>
<line x1="380" y1="380" x2="380" y2="392"/>
<line x1="432" y1="380" x2="432" y2="387"/>
<line x1="484" y1="380" x2="484" y2="392"/>
<line x1="536" y1="380" x2="536" y2="387"/>
<line x1="588" y1="380" x2="588" y2="392"/>
<line x1="640" y1="380" x2="640" y2="387"/>
<line x1="692" y1="380" x2="692" y2="392"/>
<line x1="744" y1="380" x2="744" y2="387"/>
<line x1="796" y1="380" x2="796" y2="392"/>
<line x1="848" y1="380" x2="848" y2="387"/>
<line x1="900" y1="380" x2="900" y2="392"/>
<line x1="952" y1="380" x2="952" y2="387"/>
<line x1="1004" y1="380" x2="1004" y2="392"/>
<line x1="1056" y1="380" x2="1056" y2="387"/>
<line x1="1108" y1="380" x2="1108" y2="392"/>
</g>
<!-- Selection region -->
<rect x="460" y="380" width="220" height="72" rx="2" fill="url(#sel)"/>
<line x1="460" y1="380" x2="460" y2="452" stroke="#3c82dc" stroke-width="2" stroke-opacity="0.8"/>
<line x1="680" y1="380" x2="680" y2="452" stroke="#3c82dc" stroke-width="2" stroke-opacity="0.8"/>
<!-- Playhead -->
<line x1="460" y1="372" x2="460" y2="456" stroke="#ffd230" stroke-width="2.5"/>
<polygon points="452,372 468,372 460,384" fill="#ffd230"/>
<!-- Duration label -->
<text x="570" y="422" font-family="'Courier New', monospace" font-size="18" fill="#aad4ff" text-anchor="middle" opacity="0.8">8.0s</text>
<!-- Export markers -->
<g>
<line x1="260" y1="380" x2="260" y2="452" stroke="#dc3c3c" stroke-width="2"/>
<rect x="260" y="383" width="18" height="15" rx="2" fill="#c83232"/>
<text x="269" y="395" font-family="sans-serif" font-size="11" fill="white" text-anchor="middle" font-weight="bold">1</text>
</g>
<g>
<line x1="700" y1="380" x2="700" y2="452" stroke="#dc3c3c" stroke-width="2"/>
<rect x="700" y="383" width="18" height="15" rx="2" fill="#c83232"/>
<text x="709" y="395" font-family="sans-serif" font-size="11" fill="white" text-anchor="middle" font-weight="bold">2</text>
</g>
<g>
<line x1="940" y1="380" x2="940" y2="452" stroke="#dc3c3c" stroke-width="2"/>
<rect x="940" y="383" width="18" height="15" rx="2" fill="#c83232"/>
<text x="949" y="395" font-family="sans-serif" font-size="11" fill="white" text-anchor="middle" font-weight="bold">3</text>
</g>
<!-- Scissors icon -->
<g transform="translate(554, 356) scale(0.9)" fill="none" stroke="#999" stroke-width="2" stroke-linecap="round">
<circle cx="5" cy="5" r="4"/>
<circle cx="5" cy="19" r="4"/>
<line x1="9" y1="7" x2="20" y2="17"/>
<line x1="9" y1="17" x2="20" y2="7"/>
</g>
<!-- Time labels below timeline -->
<text x="120" y="476" font-family="'Courier New', monospace" font-size="13" fill="#555">0:00</text>
<text x="448" y="476" font-family="'Courier New', monospace" font-size="13" fill="#e6a800">2:30</text>
<text x="1110" y="476" font-family="'Courier New', monospace" font-size="13" fill="#555">8:20</text>
<!-- ===== Feature pills ===== -->
<g font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="15">
<!-- Pill backgrounds -->
<rect x="260" y="520" width="120" height="30" rx="15" fill="#222" stroke="#444" stroke-width="1"/>
<rect x="400" y="520" width="130" height="30" rx="15" fill="#222" stroke="#444" stroke-width="1"/>
<rect x="550" y="520" width="120" height="30" rx="15" fill="#222" stroke="#444" stroke-width="1"/>
<rect x="690" y="520" width="140" height="30" rx="15" fill="#222" stroke="#444" stroke-width="1"/>
<rect x="850" y="520" width="130" height="30" rx="15" fill="#222" stroke="#444" stroke-width="1"/>
<!-- Pill text -->
<text x="320" y="540" fill="#aaa" text-anchor="middle">Batch export</text>
<text x="465" y="540" fill="#aaa" text-anchor="middle">Portrait crop</text>
<text x="610" y="540" fill="#aaa" text-anchor="middle">Annotation</text>
<text x="760" y="540" fill="#aaa" text-anchor="middle">Fuzzy matching</text>
<text x="915" y="540" fill="#aaa" text-anchor="middle">WebP + WAV</text>
</g>
<!-- Bottom border accent -->
<rect x="0" y="636" width="1280" height="4" fill="#ffd230" opacity="0.3"/>
</svg>

After

Width:  |  Height:  |  Size: 6.3 KiB

+10
View File
@@ -0,0 +1,10 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
+7
View File
@@ -0,0 +1,7 @@
{
"recommendations": [
"svelte.svelte-vscode",
"tauri-apps.tauri-vscode",
"rust-lang.rust-analyzer"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"svelte.enable-ts-plugin": true
}
+7
View File
@@ -0,0 +1,7 @@
# Tauri + SvelteKit + TypeScript
This template should help get you started developing with Tauri, SvelteKit and TypeScript in Vite.
## Recommended IDE Setup
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer).
+29
View File
@@ -0,0 +1,29 @@
{
"name": "client",
"version": "0.1.0",
"description": "",
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"tauri": "tauri"
},
"license": "MIT",
"dependencies": {
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-opener": "^2"
},
"devDependencies": {
"@sveltejs/adapter-static": "^3.0.6",
"@sveltejs/kit": "^2.9.0",
"@sveltejs/vite-plugin-svelte": "^5.0.0",
"svelte": "^5.0.0",
"svelte-check": "^4.0.0",
"typescript": "~5.6.2",
"vite": "^6.0.3",
"@tauri-apps/cli": "^2"
}
}
+1189
View File
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
# Generated by Tauri
# will have schema files for capabilities auto-completion
/gen/schemas
+5463
View File
File diff suppressed because it is too large Load Diff
+25
View File
@@ -0,0 +1,25 @@
[package]
name = "client"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "client_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
+3
View File
@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}
@@ -0,0 +1,10 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"opener:default"
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

+56
View File
@@ -0,0 +1,56 @@
use tauri::State;
use std::sync::Mutex;
use crate::mpv::Mpv;
pub struct MpvState(pub Mutex<Mpv>);
#[tauri::command]
pub fn mpv_start(state: State<MpvState>) -> Result<(), String> {
state.0.lock().unwrap().start()
}
#[tauri::command]
pub fn mpv_stop(state: State<MpvState>) -> Result<(), String> {
state.0.lock().unwrap().stop();
Ok(())
}
#[tauri::command]
pub fn mpv_load(state: State<MpvState>, video_url: String, audio_url: String) -> Result<(), String> {
state.0.lock().unwrap().load_file(&video_url, &audio_url)
}
#[tauri::command]
pub fn mpv_seek(state: State<MpvState>, time: f64) -> Result<(), String> {
state.0.lock().unwrap().seek(time)
}
#[tauri::command]
pub fn mpv_pause(state: State<MpvState>) -> Result<(), String> {
state.0.lock().unwrap().pause()
}
#[tauri::command]
pub fn mpv_resume(state: State<MpvState>) -> Result<(), String> {
state.0.lock().unwrap().resume()
}
#[tauri::command]
pub fn mpv_set_loop(state: State<MpvState>, a: f64, b: f64) -> Result<(), String> {
state.0.lock().unwrap().set_loop(a, b)
}
#[tauri::command]
pub fn mpv_clear_loop(state: State<MpvState>) -> Result<(), String> {
state.0.lock().unwrap().clear_loop()
}
#[tauri::command]
pub fn mpv_time_pos(state: State<MpvState>) -> Result<f64, String> {
state.0.lock().unwrap().time_pos()
}
#[tauri::command]
pub fn mpv_duration(state: State<MpvState>) -> Result<f64, String> {
state.0.lock().unwrap().get_duration()
}
+27
View File
@@ -0,0 +1,27 @@
mod mpv;
mod commands;
use commands::MpvState;
use mpv::Mpv;
use std::sync::Mutex;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.manage(MpvState(Mutex::new(Mpv::new())))
.invoke_handler(tauri::generate_handler![
commands::mpv_start,
commands::mpv_stop,
commands::mpv_load,
commands::mpv_seek,
commands::mpv_pause,
commands::mpv_resume,
commands::mpv_set_loop,
commands::mpv_clear_loop,
commands::mpv_time_pos,
commands::mpv_duration,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
+6
View File
@@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
client_lib::run()
}
+167
View File
@@ -0,0 +1,167 @@
use std::io::{BufRead, BufReader, Write};
use std::os::unix::net::UnixStream;
use std::process::{Child, Command};
use std::sync::atomic::{AtomicU64, Ordering};
use serde_json::{json, Value};
pub struct Mpv {
process: Option<Child>,
writer: Option<UnixStream>,
reader: Option<BufReader<UnixStream>>,
socket_path: String,
next_id: AtomicU64,
}
impl Mpv {
pub fn new() -> Self {
let socket_path = format!("/tmp/8cut-mpv-{}", std::process::id());
Mpv {
process: None,
writer: None,
reader: None,
socket_path,
next_id: AtomicU64::new(1),
}
}
pub fn start(&mut self) -> Result<(), String> {
self.stop();
let child = Command::new("mpv")
.args([
"--idle=yes",
"--force-window=no",
"--vo=null",
"--keep-open=yes",
&format!("--input-ipc-server={}", self.socket_path),
])
.spawn()
.map_err(|e| format!("Failed to start mpv: {e}"))?;
self.process = Some(child);
// Wait for socket
for _ in 0..50 {
std::thread::sleep(std::time::Duration::from_millis(100));
if let Ok(stream) = UnixStream::connect(&self.socket_path) {
stream.set_nonblocking(false).ok();
let reader_stream = stream.try_clone().map_err(|e| e.to_string())?;
self.writer = Some(stream);
self.reader = Some(BufReader::new(reader_stream));
return Ok(());
}
}
Err("Timeout waiting for mpv IPC socket".into())
}
pub fn stop(&mut self) {
if let Some(ref mut child) = self.process {
child.kill().ok();
child.wait().ok();
}
self.process = None;
self.writer = None;
self.reader = None;
std::fs::remove_file(&self.socket_path).ok();
}
/// Send a command and wait for the matching response (by request_id).
/// Skips over asynchronous mpv events while waiting.
fn send_and_recv(&mut self, cmd: Value) -> Result<Value, String> {
let id = self.next_id.fetch_add(1, Ordering::Relaxed);
let writer = self.writer.as_mut().ok_or("mpv not running")?;
let reader = self.reader.as_mut().ok_or("mpv not running")?;
let mut msg_val = cmd;
msg_val["request_id"] = json!(id);
let mut msg = serde_json::to_string(&msg_val).unwrap();
msg.push('\n');
writer.write_all(msg.as_bytes()).map_err(|e| e.to_string())?;
// Read lines until we find the response matching our request_id
let mut line = String::new();
loop {
line.clear();
reader.read_line(&mut line).map_err(|e| e.to_string())?;
let parsed: Value = serde_json::from_str(&line).map_err(|e| e.to_string())?;
// mpv events have "event" key, responses have "request_id"
if parsed.get("request_id").and_then(|v| v.as_u64()) == Some(id) {
return Ok(parsed);
}
// Otherwise it's an async event — skip it
}
}
pub fn command(&mut self, args: &[&str]) -> Result<(), String> {
let resp = self.send_and_recv(json!({ "command": args }))?;
if resp.get("error").and_then(|e| e.as_str()) != Some("success") {
return Err(format!("mpv error: {}", resp.get("error").unwrap_or(&Value::Null)));
}
Ok(())
}
pub fn set_property(&mut self, name: &str, value: Value) -> Result<(), String> {
let resp = self.send_and_recv(json!({ "command": ["set_property", name, value] }))?;
if resp.get("error").and_then(|e| e.as_str()) != Some("success") {
return Err(format!("mpv error: {}", resp.get("error").unwrap_or(&Value::Null)));
}
Ok(())
}
pub fn get_property(&mut self, name: &str) -> Result<Value, String> {
let resp = self.send_and_recv(json!({ "command": ["get_property", name] }))?;
if resp.get("error").and_then(|e| e.as_str()) != Some("success") {
return Err(format!("mpv error: {}", resp.get("error").unwrap_or(&Value::Null)));
}
Ok(resp.get("data").cloned().unwrap_or(Value::Null))
}
pub fn load_file(&mut self, video_url: &str, audio_url: &str) -> Result<(), String> {
let options = format!("audio-file={}", audio_url);
let resp = self.send_and_recv(json!({
"command": ["loadfile", video_url, "replace", -1, options]
}))?;
if resp.get("error").and_then(|e| e.as_str()) != Some("success") {
return Err(format!("mpv error: {}", resp.get("error").unwrap_or(&Value::Null)));
}
Ok(())
}
pub fn seek(&mut self, time: f64) -> Result<(), String> {
self.command(&["seek", &time.to_string(), "absolute"])
}
pub fn pause(&mut self) -> Result<(), String> {
self.set_property("pause", json!(true))
}
pub fn resume(&mut self) -> Result<(), String> {
self.set_property("pause", json!(false))
}
pub fn set_loop(&mut self, a: f64, b: f64) -> Result<(), String> {
self.set_property("ab-loop-a", json!(a))?;
self.set_property("ab-loop-b", json!(b))
}
pub fn clear_loop(&mut self) -> Result<(), String> {
self.set_property("ab-loop-a", json!("no"))?;
self.set_property("ab-loop-b", json!("no"))
}
pub fn time_pos(&mut self) -> Result<f64, String> {
let val = self.get_property("time-pos")?;
val.as_f64().ok_or("time-pos not a number".into())
}
pub fn get_duration(&mut self) -> Result<f64, String> {
let val = self.get_property("duration")?;
val.as_f64().ok_or("duration not a number".into())
}
}
impl Drop for Mpv {
fn drop(&mut self) {
self.stop();
}
}
+35
View File
@@ -0,0 +1,35 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "8cut",
"version": "0.1.0",
"identifier": "com.ethanfel.8cut",
"build": {
"beforeDevCommand": "pnpm dev",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "pnpm build",
"frontendDist": "../build"
},
"app": {
"windows": [
{
"title": "8-cut",
"width": 1200,
"height": 800
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": ["deb", "appimage"],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Tauri + SvelteKit + Typescript App</title>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
+113
View File
@@ -0,0 +1,113 @@
<script lang="ts" module>
// Module-level export so App can call doExport via bind:this
</script>
<script lang="ts">
import { startExport } from "$lib/api";
import {
currentFile, cursor, clips, spread, shortSide, portraitRatio,
cropCenter, format, label, category, clipName, profile,
hwEncode,
exportStatus, exportCompleted, exportTotal, subprofiles
} from "$lib/stores";
const CATEGORIES = ["", "Human", "Animal", "Vehicle", "Tool", "Music", "Nature", "Sport", "Other"];
const RATIOS = ["Off", "9:16", "4:5", "1:1"];
export async function doExport(folderSuffix: string = "") {
if (!$currentFile) return;
$exportStatus = "running";
$exportCompleted = 0;
$exportTotal = $clips;
const req = {
input_path: `${$currentFile.root}/${$currentFile.path}`,
cursor: $cursor,
name: $clipName || $currentFile.name.replace(/\.[^.]+$/, ""),
clips: $clips,
spread: $spread,
short_side: $shortSide,
portrait_ratio: $portraitRatio,
crop_center: $cropCenter,
format: $format,
label: $label,
category: $category,
profile: $profile,
folder_suffix: folderSuffix,
encoder: $hwEncode ? "h264_nvenc" : "libx264",
};
try {
await startExport(req);
} catch (e) {
$exportStatus = "error";
console.error(e);
}
}
</script>
<div class="export-panel">
<div class="row">
<button onclick={() => doExport()} disabled={$exportStatus === "running"}>
Export{#if $exportStatus === "running"} ({$exportCompleted}/{$exportTotal}){/if}
</button>
{#each $subprofiles as sub}
<button onclick={() => doExport(sub)} title="Export {sub}">
{sub}
</button>
{/each}
</div>
<div class="row">
<label>Clips <input type="number" bind:value={$clips} min="1" max="99" /></label>
<label>Spread <input type="number" bind:value={$spread} min="2" max="8" step="0.5" /></label>
<label>Size <input type="number" bind:value={$shortSide} min="0" max="4320" step="64" /></label>
<label>Ratio
<select bind:value={$portraitRatio}>
{#each RATIOS as r}
<option value={r === "Off" ? null : r}>{r}</option>
{/each}
</select>
</label>
</div>
<div class="row">
<label>Label <input type="text" bind:value={$label} /></label>
<label>Category
<select bind:value={$category}>
{#each CATEGORIES as c}
<option value={c}>{c || "---"}</option>
{/each}
</select>
</label>
<label>Format
<select bind:value={$format}>
<option>MP4</option>
<option>WebP sequence</option>
</select>
</label>
<label><input type="checkbox" bind:checked={$hwEncode} /> GPU</label>
</div>
</div>
<style>
.export-panel {
display: flex;
flex-direction: column;
gap: 4px;
padding: 4px;
font-size: 12px;
}
.row {
display: flex;
gap: 6px;
align-items: center;
flex-wrap: wrap;
}
label { display: flex; align-items: center; gap: 2px; }
input[type="number"] { width: 50px; background: #2d2d2d; color: #e0e0e0; border: 1px solid #444; }
input[type="text"] { width: 120px; background: #2d2d2d; color: #e0e0e0; border: 1px solid #444; }
select { background: #2d2d2d; color: #e0e0e0; border: 1px solid #444; }
button { background: #0066cc; color: white; border: none; padding: 4px 12px; cursor: pointer; }
button:disabled { background: #444; }
</style>
+173
View File
@@ -0,0 +1,173 @@
<script lang="ts">
import { onMount } from "svelte";
import { getFiles, getRoots, getHidden, getMarkers, hideFile, unhideFile } from "$lib/api";
import {
files, roots, hiddenFiles, currentFile, showHidden,
profile, markers, visibleFiles
} from "$lib/stores";
let selectedRoot = $state("");
let currentFolder = $state("");
onMount(async () => {
$roots = await getRoots();
if ($roots.length) {
selectedRoot = $roots[0];
await loadFiles();
}
});
// Reload hidden files when profile changes
$effect(() => {
void $profile;
if (selectedRoot) {
loadFiles();
}
});
async function loadFiles() {
$files = await getFiles(selectedRoot);
const hidden = await getHidden($profile);
$hiddenFiles = new Set(hidden);
}
// Derive subfolders and files at current folder level
let subfolders = $derived.by(() => {
const prefix = currentFolder ? currentFolder + "/" : "";
const folderSet = new Set<string>();
for (const f of $visibleFiles) {
if (!f.path.startsWith(prefix)) continue;
const rest = f.path.slice(prefix.length);
const slashIdx = rest.indexOf("/");
if (slashIdx !== -1) {
folderSet.add(rest.slice(0, slashIdx));
}
}
return [...folderSet].sort();
});
let currentFiles = $derived.by(() => {
const prefix = currentFolder ? currentFolder + "/" : "";
return $visibleFiles.filter(f => {
if (!f.path.startsWith(prefix)) return false;
const rest = f.path.slice(prefix.length);
return !rest.includes("/"); // only direct children
});
});
async function selectFile(file: typeof $files[0]) {
$currentFile = file;
$markers = await getMarkers(file.name, $profile);
}
function navigateToFolder(name: string) {
currentFolder = currentFolder ? currentFolder + "/" + name : name;
}
function navigateUp() {
const idx = currentFolder.lastIndexOf("/");
currentFolder = idx === -1 ? "" : currentFolder.slice(0, idx);
}
function formatSize(bytes: number): string {
if (bytes > 1e9) return (bytes / 1e9).toFixed(1) + " GB";
if (bytes > 1e6) return (bytes / 1e6).toFixed(0) + " MB";
return (bytes / 1e3).toFixed(0) + " KB";
}
async function toggleHidden(file: typeof $files[0]) {
if ($hiddenFiles.has(file.name)) {
await unhideFile(file.name, $profile);
} else {
await hideFile(file.name, $profile);
}
await loadFiles();
}
</script>
<div class="file-browser">
<div class="controls">
<select bind:value={selectedRoot} onchange={() => { currentFolder = ""; loadFiles(); }}>
{#each $roots as root}
<option value={root}>{root}</option>
{/each}
</select>
<label><input type="checkbox" bind:checked={$showHidden} /> Hidden</label>
</div>
{#if currentFolder}
<div class="breadcrumb" onclick={navigateUp}>.. / {currentFolder}</div>
{/if}
<ul class="file-list">
{#each subfolders as folder}
<li class="folder" onclick={() => navigateToFolder(folder)}>
<span class="name">{folder}/</span>
<span class="badge">dir</span>
</li>
{/each}
{#each currentFiles as file}
<li
class:selected={$currentFile?.path === file.path}
onclick={() => selectFile(file)}
oncontextmenu={(e) => { e.preventDefault(); toggleHidden(file); }}
>
<span class="name">{file.name}</span>
<span class="size">{formatSize(file.size)}</span>
</li>
{/each}
</ul>
</div>
<style>
.file-browser {
display: flex;
flex-direction: column;
height: 100%;
min-width: 200px;
}
.controls {
display: flex;
gap: 4px;
padding: 4px;
align-items: center;
}
.controls select {
flex: 1;
background: #2d2d2d;
color: #e0e0e0;
border: 1px solid #444;
padding: 2px;
}
.breadcrumb {
padding: 3px 8px;
font-size: 11px;
color: #88aaff;
cursor: pointer;
background: #252525;
border-bottom: 1px solid #333;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.breadcrumb:hover { background: #2a2a2a; }
.file-list {
list-style: none;
padding: 0;
margin: 0;
overflow-y: auto;
flex: 1;
}
.file-list li {
padding: 4px 8px;
cursor: pointer;
display: flex;
justify-content: space-between;
font-size: 12px;
white-space: nowrap;
}
.file-list li:hover { background: #333; }
.file-list li.selected { background: #0066cc; }
.file-list li.folder { color: #88aaff; }
.name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.size { flex-shrink: 0; margin-left: 8px; color: #888; font-size: 11px; }
.badge { flex-shrink: 0; margin-left: 8px; color: #666; font-size: 10px; }
</style>
+93
View File
@@ -0,0 +1,93 @@
<script lang="ts">
import { onMount } from "svelte";
import { getProfiles, setServer, getServer } from "$lib/api";
import { profile, subprofiles, serverUrl } from "$lib/stores";
import { saveSettings } from "$lib/settings";
let profiles = $state<string[]>([]);
let serverInput = $state(getServer());
onMount(async () => {
serverInput = getServer();
try {
profiles = await getProfiles();
if (profiles.length && !profiles.includes($profile)) {
$profile = profiles[0];
}
} catch { /* server not reachable yet */ }
});
function applyServer() {
const url = serverInput.replace(/\/+$/, "");
setServer(url);
$serverUrl = url;
saveSettings();
// Reload profiles from new server
getProfiles().then(p => { profiles = p; }).catch(() => {});
}
function addSubprofile() {
const name = prompt("Subprofile suffix:");
if (name && !$subprofiles.includes(name)) {
$subprofiles = [...$subprofiles, name];
}
}
function removeSubprofile(name: string) {
$subprofiles = $subprofiles.filter(s => s !== name);
}
</script>
<div class="profile-bar">
<input
class="server-input"
type="text"
bind:value={serverInput}
onkeydown={(e) => { if (e.key === "Enter") applyServer(); }}
placeholder="http://host:8000"
/>
<button onclick={applyServer}>Set</button>
<select bind:value={$profile}>
{#each profiles as p}
<option value={p}>{p}</option>
{/each}
</select>
<span class="subs">
{#each $subprofiles as sub}
<span class="sub-tag" oncontextmenu={(e) => { e.preventDefault(); removeSubprofile(sub); }}>
{sub}
</span>
{/each}
<button onclick={addSubprofile}>+</button>
</span>
</div>
<style>
.profile-bar {
display: flex;
align-items: center;
gap: 8px;
padding: 4px;
font-size: 12px;
}
.server-input {
width: 180px;
background: #2d2d2d;
color: #e0e0e0;
border: 1px solid #444;
padding: 2px 4px;
font-size: 11px;
}
select { background: #2d2d2d; color: #e0e0e0; border: 1px solid #444; }
.subs { display: flex; gap: 4px; align-items: center; }
.sub-tag {
background: #444;
padding: 2px 6px;
border-radius: 3px;
cursor: context-menu;
font-size: 11px;
}
button { background: #333; color: #e0e0e0; border: 1px solid #555; padding: 1px 6px; cursor: pointer; }
</style>
+170
View File
@@ -0,0 +1,170 @@
<script lang="ts">
import { onMount } from "svelte";
import {
duration, cursor, playPos, markers, clips, spread, locked, clipSpan
} from "$lib/stores";
let {
onCursorChange = (_time: number) => {},
onSeek = (_time: number) => {},
onMarkerClick = (_marker: { start_time: number; output_path: string }) => {},
onMarkerDelete = (_outputPath: string) => {},
} = $props<{
onCursorChange?: (time: number) => void;
onSeek?: (time: number) => void;
onMarkerClick?: (marker: { start_time: number; output_path: string }) => void;
onMarkerDelete?: (outputPath: string) => void;
}>();
let canvas: HTMLCanvasElement;
let ctx: CanvasRenderingContext2D;
let dragging = $state(false);
const HEIGHT = 160;
function timeToX(t: number): number {
if ($duration <= 0) return 0;
return (t / $duration) * canvas.width;
}
function xToTime(x: number): number {
if ($duration <= 0) return 0;
return Math.max(0, Math.min($duration, (x / canvas.width) * $duration));
}
function draw() {
if (!ctx) return;
const w = canvas.width;
const h = canvas.height;
ctx.clearRect(0, 0, w, h);
// Background
ctx.fillStyle = "#1a1a1a";
ctx.fillRect(0, 0, w, h);
// Clip span region
if ($duration > 0) {
const x0 = timeToX($cursor);
const x1 = timeToX($cursor + $clipSpan);
ctx.fillStyle = "rgba(0, 100, 200, 0.15)";
ctx.fillRect(x0, 0, x1 - x0, h);
}
// Markers
for (const m of $markers) {
const x = timeToX(m.start_time);
ctx.fillStyle = "#22aa44";
ctx.fillRect(x - 1, 0, 3, h);
}
// Cursor
if ($duration > 0) {
const cx = timeToX($cursor);
ctx.fillStyle = "#ff4444";
ctx.fillRect(cx - 1, 0, 3, h);
}
// Play position
if ($playPos !== null && $duration > 0) {
const px = timeToX($playPos);
ctx.fillStyle = "#ffaa00";
ctx.fillRect(px - 1, 0, 2, h);
}
// Time labels
if ($duration > 0) {
ctx.fillStyle = "#888";
ctx.font = "11px monospace";
const step = Math.max(10, Math.pow(10, Math.floor(Math.log10($duration / 5))));
for (let t = 0; t <= $duration; t += step) {
const x = timeToX(t);
ctx.fillText(formatTime(t), x + 2, h - 4);
ctx.fillRect(x, h - 16, 1, 16);
}
}
}
function formatTime(s: number): string {
const m = Math.floor(s / 60);
const sec = (Math.floor(s % 60 * 10) / 10).toFixed(1);
return `${m}:${sec.padStart(4, "0")}`;
}
function handleMouseDown(e: MouseEvent) {
if ($locked) return;
dragging = true;
const time = xToTime(e.offsetX);
$cursor = time;
onCursorChange(time);
}
function handleMouseMove(e: MouseEvent) {
if (!dragging || $locked) return;
const time = xToTime(e.offsetX);
$cursor = time;
onCursorChange(time);
}
function handleMouseUp() {
dragging = false;
}
function handleDblClick(e: MouseEvent) {
const time = xToTime(e.offsetX);
for (const m of $markers) {
const mx = timeToX(m.start_time);
if (Math.abs(e.offsetX - mx) < 8) {
onMarkerClick(m);
return;
}
}
onSeek(time);
}
function handleContextMenu(e: MouseEvent) {
e.preventDefault();
for (const m of $markers) {
const mx = timeToX(m.start_time);
if (Math.abs(e.offsetX - mx) < 8) {
onMarkerDelete(m.output_path);
return;
}
}
}
// Redraw on any state change
$effect(() => {
void $duration; void $cursor; void $playPos; void $markers; void $clips; void $spread; void $clipSpan;
draw();
});
onMount(() => {
ctx = canvas.getContext("2d")!;
const obs = new ResizeObserver(() => {
canvas.width = canvas.clientWidth;
canvas.height = HEIGHT;
draw();
});
obs.observe(canvas);
return () => obs.disconnect();
});
</script>
<canvas
bind:this={canvas}
style="width:100%;height:{HEIGHT}px"
onmousedown={handleMouseDown}
onmousemove={handleMouseMove}
onmouseup={handleMouseUp}
onmouseleave={handleMouseUp}
ondblclick={handleDblClick}
oncontextmenu={handleContextMenu}
></canvas>
<style>
canvas {
display: block;
background: #1a1a1a;
cursor: crosshair;
}
</style>
+158
View File
@@ -0,0 +1,158 @@
const DEFAULT_SERVER = "http://192.168.1.51:8000";
let serverUrl = DEFAULT_SERVER;
export function setServer(url: string) {
serverUrl = url.replace(/\/+$/, "");
}
export function getServer(): string {
return serverUrl;
}
async function get<T>(path: string): Promise<T> {
const res = await fetch(`${serverUrl}${path}`);
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
return res.json();
}
async function post<T>(path: string, body?: unknown): Promise<T> {
const res = await fetch(`${serverUrl}${path}`, {
method: "POST",
headers: body ? { "Content-Type": "application/json" } : {},
body: body ? JSON.stringify(body) : undefined,
});
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
return res.json();
}
async function del<T>(path: string): Promise<T> {
const res = await fetch(`${serverUrl}${path}`, { method: "DELETE" });
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
return res.json();
}
// --- Files ---
export interface VideoFile {
name: string;
path: string;
root: string;
size: number;
}
export function getRoots(): Promise<string[]> {
return get("/api/roots");
}
export function getFiles(root?: string): Promise<VideoFile[]> {
const q = root ? `?root=${encodeURIComponent(root)}` : "";
return get(`/api/files${q}`);
}
// For {path:path} routes, encode each segment individually to preserve slashes
function encodePath(p: string): string {
return p.split("/").map(encodeURIComponent).join("/");
}
export function streamUrl(path: string, root: string, quality: string): string {
return `${serverUrl}/api/stream/${encodePath(path)}?root=${encodeURIComponent(root)}&quality=${quality}`;
}
export function audioUrl(path: string, root: string): string {
return `${serverUrl}/api/audio/${encodePath(path)}?root=${encodeURIComponent(root)}`;
}
/** Poll cache status until both video and audio are ready. */
export async function waitForCache(
path: string, root: string, quality: string,
signal: AbortSignal, interval = 2000
): Promise<void> {
const url = `${serverUrl}/api/cache/status/${encodePath(path)}?root=${encodeURIComponent(root)}`;
// Trigger transcode/audio extraction by hitting stream+audio once
await fetch(streamUrl(path, root, quality), { signal }).catch(() => {});
await fetch(audioUrl(path, root), { signal }).catch(() => {});
while (!signal.aborted) {
const res = await fetch(url, { signal });
const status = await res.json();
if (status[quality] === "ready" && status.audio === "ready") return;
await new Promise(r => setTimeout(r, interval));
}
throw new Error("Aborted");
}
export function cacheStatus(path: string, root: string): Promise<Record<string, string>> {
return get(`/api/cache/status/${encodePath(path)}?root=${encodeURIComponent(root)}`);
}
// --- Markers & Profiles ---
export interface Marker {
start_time: number;
marker_number: number;
output_path: string;
}
export function getMarkers(filename: string, profile: string = "default"): Promise<Marker[]> {
return get(`/api/markers/${encodeURIComponent(filename)}?profile=${encodeURIComponent(profile)}`);
}
export function getProfiles(): Promise<string[]> {
return get("/api/profiles");
}
export function getLabels(): Promise<string[]> {
return get("/api/labels");
}
// --- Export ---
export interface ExportRequest {
input_path: string;
cursor: number;
name: string;
clips?: number;
spread?: number;
short_side?: number | null;
portrait_ratio?: string | null;
crop_center?: number;
format?: string;
label?: string;
category?: string;
profile?: string;
folder_suffix?: string;
encoder?: string;
}
export function startExport(req: ExportRequest): Promise<{ job_id: string }> {
return post("/api/export", req);
}
export function getExportStatus(jobId: string): Promise<{
status: string;
total: number;
completed: number;
outputs: string[];
error?: string;
}> {
return get(`/api/export/${jobId}`);
}
export function deleteExport(outputPath: string): Promise<{ deleted: string }> {
return del(`/api/export?output_path=${encodeURIComponent(outputPath)}`);
}
// --- Hidden ---
export function hideFile(filename: string, profile: string = "default"): Promise<unknown> {
return post(`/api/hidden/${encodeURIComponent(filename)}?profile=${encodeURIComponent(profile)}`);
}
export function unhideFile(filename: string, profile: string = "default"): Promise<unknown> {
return del(`/api/hidden/${encodeURIComponent(filename)}?profile=${encodeURIComponent(profile)}`);
}
export function getHidden(profile: string = "default"): Promise<string[]> {
return get(`/api/hidden?profile=${encodeURIComponent(profile)}`);
}
+41
View File
@@ -0,0 +1,41 @@
import { invoke } from "@tauri-apps/api/core";
export async function mpvStart(): Promise<void> {
return invoke("mpv_start");
}
export async function mpvStop(): Promise<void> {
return invoke("mpv_stop");
}
export async function mpvLoad(videoUrl: string, audioUrl: string): Promise<void> {
return invoke("mpv_load", { videoUrl, audioUrl });
}
export async function mpvSeek(time: number): Promise<void> {
return invoke("mpv_seek", { time });
}
export async function mpvPause(): Promise<void> {
return invoke("mpv_pause");
}
export async function mpvResume(): Promise<void> {
return invoke("mpv_resume");
}
export async function mpvSetLoop(a: number, b: number): Promise<void> {
return invoke("mpv_set_loop", { a, b });
}
export async function mpvClearLoop(): Promise<void> {
return invoke("mpv_clear_loop");
}
export async function mpvTimePos(): Promise<number> {
return invoke("mpv_time_pos");
}
export async function mpvDuration(): Promise<number> {
return invoke("mpv_duration");
}
+58
View File
@@ -0,0 +1,58 @@
import {
serverUrl, quality, clips, spread, shortSide, portraitRatio,
format, hwEncode, profile, subprofiles
} from "./stores";
import { setServer } from "./api";
import { get } from "svelte/store";
const KEY = "8cut-settings";
interface Settings {
serverUrl: string;
quality: string;
clips: number;
spread: number;
shortSide: number | null;
portraitRatio: string | null;
format: string;
hwEncode: boolean;
profile: string;
subprofiles: string[];
}
export function saveSettings() {
const data: Settings = {
serverUrl: get(serverUrl),
quality: get(quality),
clips: get(clips),
spread: get(spread),
shortSide: get(shortSide),
portraitRatio: get(portraitRatio),
format: get(format),
hwEncode: get(hwEncode),
profile: get(profile),
subprofiles: get(subprofiles),
};
localStorage.setItem(KEY, JSON.stringify(data));
}
export function loadSettings() {
const raw = localStorage.getItem(KEY);
if (!raw) return;
try {
const data: Settings = JSON.parse(raw);
if (data.serverUrl) {
serverUrl.set(data.serverUrl);
setServer(data.serverUrl);
}
if (data.quality) quality.set(data.quality);
if (data.clips) clips.set(data.clips);
if (data.spread) spread.set(data.spread);
if (data.shortSide !== undefined) shortSide.set(data.shortSide);
if (data.portraitRatio !== undefined) portraitRatio.set(data.portraitRatio);
if (data.format) format.set(data.format);
if (data.hwEncode !== undefined) hwEncode.set(data.hwEncode);
if (data.profile) profile.set(data.profile);
if (data.subprofiles) subprofiles.set(data.subprofiles);
} catch { /* ignore corrupt settings */ }
}
+66
View File
@@ -0,0 +1,66 @@
import { writable, derived } from "svelte/store";
import type { VideoFile, Marker } from "./api";
// --- Connection ---
export const serverUrl = writable("http://192.168.1.51:8000");
// --- Files ---
export const roots = writable<string[]>([]);
export const files = writable<VideoFile[]>([]);
export const hiddenFiles = writable<Set<string>>(new Set());
export const currentFile = writable<VideoFile | null>(null);
export const hideExported = writable(false);
export const showHidden = writable(false);
// --- Playback ---
export const duration = writable(0);
export const cursor = writable(0);
export const playPos = writable<number | null>(null);
export const playing = writable(false);
export const quality = writable("low");
// --- Timeline ---
export const markers = writable<Marker[]>([]);
export const locked = writable(false);
// --- Export settings ---
export const clips = writable(3);
export const spread = writable(3.0);
export const shortSide = writable<number | null>(512);
export const portraitRatio = writable<string | null>(null);
export const cropCenter = writable(0.5);
export const format = writable("MP4");
export const hwEncode = writable(false);
export const label = writable("");
export const category = writable("");
export const clipName = writable("");
export const exportFolder = writable("");
export const encoder = writable("libx264");
export const trackSubject = writable(false);
export const randPortrait = writable(false);
export const randSquare = writable(false);
// --- Profiles ---
export const profile = writable("default");
export const subprofiles = writable<string[]>([]);
// --- Export progress ---
export const exportStatus = writable<string>("idle"); // idle | running | done | error
export const exportCompleted = writable(0);
export const exportTotal = writable(0);
// --- Derived ---
export const clipSpan = derived(
[clips, spread],
([$clips, $spread]) => 8.0 + ($clips - 1) * $spread
);
export const visibleFiles = derived(
[files, hiddenFiles, showHidden],
([$files, $hidden, $showHidden]) => {
return $files.filter(f => {
if (!$showHidden && $hidden.has(f.name)) return false;
return true;
});
}
);
+48
View File
@@ -0,0 +1,48 @@
import { getServer } from "./api";
import { exportStatus, exportCompleted } from "./stores";
let socket: WebSocket | null = null;
let reconnectDelay = 2000;
export function connectExportWs() {
const wsUrl = getServer().replace(/^http/, "ws") + "/ws/export";
socket = new WebSocket(wsUrl);
socket.onopen = () => {
reconnectDelay = 2000; // reset backoff on successful connect
};
socket.onmessage = (event) => {
try {
const msg = JSON.parse(event.data);
switch (msg.type) {
case "clip_done":
exportCompleted.update(n => n + 1);
break;
case "all_done":
exportStatus.set("done");
break;
case "error":
exportStatus.set("error");
console.error("Export error:", msg.msg);
break;
}
} catch (e) {
console.error("Failed to parse WebSocket message:", e);
}
};
socket.onclose = () => {
// Reconnect with exponential backoff, max 30s
setTimeout(connectExportWs, reconnectDelay);
reconnectDelay = Math.min(reconnectDelay * 2, 30000);
};
}
export function disconnectExportWs() {
if (socket) {
socket.onclose = null; // prevent reconnect
socket.close();
socket = null;
}
}
+5
View File
@@ -0,0 +1,5 @@
// Tauri doesn't have a Node.js server to do proper SSR
// so we use adapter-static with a fallback to index.html to put the site in SPA mode
// See: https://svelte.dev/docs/kit/single-page-apps
// See: https://v2.tauri.app/start/frontend/sveltekit/ for more info
export const ssr = false;
+251
View File
@@ -0,0 +1,251 @@
<script lang="ts">
import { onMount, onDestroy } from "svelte";
import FileBrowser from "../components/FileBrowser.svelte";
import Timeline from "../components/Timeline.svelte";
import ExportPanel from "../components/ExportPanel.svelte";
import ProfileBar from "../components/ProfileBar.svelte";
import { mpvStart, mpvLoad, mpvSeek, mpvPause, mpvResume, mpvSetLoop, mpvClearLoop, mpvTimePos, mpvDuration } from "$lib/mpv";
import { streamUrl, audioUrl, waitForCache, deleteExport, getMarkers } from "$lib/api";
import { connectExportWs, disconnectExportWs } from "$lib/ws";
import { loadSettings, saveSettings } from "$lib/settings";
import {
currentFile, cursor, duration, playPos, playing, quality,
clips, spread, locked, markers, profile, clipSpan, subprofiles
} from "$lib/stores";
let pollInterval: ReturnType<typeof setInterval>;
let exportPanelRef: ExportPanel;
onMount(async () => {
loadSettings();
await mpvStart();
connectExportWs();
// Poll mpv for time position
pollInterval = setInterval(async () => {
if ($playing) {
try {
$playPos = await mpvTimePos();
} catch { /* mpv not ready */ }
}
}, 50);
// Auto-save settings on changes
const unsubs = [
quality.subscribe(() => saveSettings()),
clips.subscribe(() => saveSettings()),
spread.subscribe(() => saveSettings()),
profile.subscribe(() => saveSettings()),
subprofiles.subscribe(() => saveSettings()),
];
return () => unsubs.forEach(u => u());
});
onDestroy(() => {
clearInterval(pollInterval);
disconnectExportWs();
});
// Load file into mpv when currentFile OR quality changes
let loadAbort: AbortController | null = null;
$effect(() => {
const file = $currentFile;
const q = $quality;
if (file) {
// Cancel any previous polling
loadAbort?.abort();
const ac = new AbortController();
loadAbort = ac;
const vUrl = streamUrl(file.path, file.root, q);
const aUrl = audioUrl(file.path, file.root);
waitForCache(file.path, file.root, q, ac.signal).then(() =>
mpvLoad(vUrl, aUrl)
).then(async () => {
await new Promise(r => setTimeout(r, 500));
try { $duration = await mpvDuration(); } catch {}
}).catch(() => {}); // aborted or error
}
});
async function handleCursorChange(time: number) {
await mpvSeek(time);
}
async function handlePlay() {
const a = $cursor;
const b = $cursor + $clipSpan;
await mpvSeek(a);
await mpvSetLoop(a, b);
await mpvResume();
$playing = true;
}
async function handlePause() {
await mpvPause();
await mpvClearLoop();
$playing = false;
}
async function handleMarkerClick(m: { start_time: number; output_path: string }) {
if ($locked) {
const span = 8.0 + ($clips - 1) * $spread;
$cursor = m.start_time + span;
await mpvSeek($cursor);
} else {
$cursor = m.start_time;
await mpvSeek(m.start_time);
}
}
async function handleMarkerDelete(outputPath: string) {
await deleteExport(outputPath);
if ($currentFile) {
$markers = await getMarkers($currentFile.name, $profile);
}
}
function handleKeydown(e: KeyboardEvent) {
const tag = (e.target as HTMLElement).tagName;
if (tag === "INPUT" || tag === "SELECT" || tag === "TEXTAREA") return;
switch (e.key) {
case " ":
e.preventDefault();
$playing ? handlePause() : handlePlay();
break;
case "e":
case "E":
exportPanelRef?.doExport();
break;
case "ArrowLeft":
$cursor = Math.max(0, $cursor - 1);
handleCursorChange($cursor);
break;
case "ArrowRight":
$cursor = Math.min($duration, $cursor + 1);
handleCursorChange($cursor);
break;
}
const num = parseInt(e.key);
if (num >= 1 && num <= 9) {
const idx = num - 1;
if (idx < $subprofiles.length) {
exportPanelRef?.doExport($subprofiles[idx]);
}
}
}
function fmtTime(s: number): string {
const m = Math.floor(s / 60);
const sec = (Math.floor(s % 60 * 10) / 10).toFixed(1);
return `${m}:${sec.padStart(4, "0")}`;
}
</script>
<svelte:window onkeydown={handleKeydown} />
<main>
<div class="layout">
<div class="sidebar">
<FileBrowser />
</div>
<div class="content">
<ProfileBar />
<div class="player-area">
<div class="video-placeholder">
{#if $currentFile}
<p>{$currentFile.name}</p>
{:else}
<p>Select a file</p>
{/if}
</div>
</div>
<Timeline
onCursorChange={handleCursorChange}
onSeek={handleCursorChange}
onMarkerClick={handleMarkerClick}
onMarkerDelete={handleMarkerDelete}
/>
<div class="transport">
<button onclick={handlePlay} disabled={!$currentFile}>Play</button>
<button onclick={handlePause}>Pause</button>
<button onclick={() => $locked = !$locked}>
{$locked ? "Locked" : "Unlocked"}
</button>
<span class="time">
{#if $duration > 0}
{fmtTime($cursor)} / {fmtTime($duration)}
{/if}
</span>
<select bind:value={$quality} style="margin-left:auto">
<option value="potato">480p</option>
<option value="low">720p</option>
<option value="medium">1080p</option>
<option value="high">Original</option>
</select>
</div>
<ExportPanel bind:this={exportPanelRef} />
</div>
</div>
</main>
<style>
:global(body) {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: #1e1e1e;
color: #e0e0e0;
}
main { height: 100vh; overflow: hidden; }
.layout {
display: flex;
height: 100%;
}
.sidebar {
width: 220px;
min-width: 220px;
flex-shrink: 0;
border-right: 1px solid #333;
overflow: hidden;
}
.content {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.player-area {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
background: #000;
min-height: 200px;
}
.video-placeholder {
color: #666;
text-align: center;
}
.transport {
display: flex;
align-items: center;
gap: 6px;
padding: 4px 8px;
background: #222;
}
.transport button {
background: #333;
color: #e0e0e0;
border: 1px solid #555;
padding: 4px 10px;
cursor: pointer;
}
.time {
font-family: monospace;
font-size: 13px;
}
select { background: #2d2d2d; color: #e0e0e0; border: 1px solid #444; }
</style>
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

+6
View File
@@ -0,0 +1,6 @@
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

+18
View File
@@ -0,0 +1,18 @@
// Tauri doesn't have a Node.js server to do proper SSR
// so we use adapter-static with a fallback to index.html to put the site in SPA mode
// See: https://svelte.dev/docs/kit/single-page-apps
// See: https://v2.tauri.app/start/frontend/sveltekit/ for more info
import adapter from "@sveltejs/adapter-static";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter({
fallback: "index.html",
}),
},
};
export default config;
+19
View File
@@ -0,0 +1,19 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "bundler"
}
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}
+32
View File
@@ -0,0 +1,32 @@
import { defineConfig } from "vite";
import { sveltekit } from "@sveltejs/kit/vite";
// @ts-expect-error process is a nodejs global
const host = process.env.TAURI_DEV_HOST;
// https://vite.dev/config/
export default defineConfig(async () => ({
plugins: [sveltekit()],
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent Vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
host: host || false,
hmr: host
? {
protocol: "ws",
host,
port: 1421,
}
: undefined,
watch: {
// 3. tell Vite to ignore watching `src-tauri`
ignored: ["**/src-tauri/**"],
},
},
}));
View File
+55
View File
@@ -0,0 +1,55 @@
import json
import os
def build_annotation_json_path(folder: str) -> str:
return os.path.join(folder, "dataset.json")
def remove_clip_annotation(folder: str, clip_path: str) -> None:
"""Remove the entry for *clip_path* from <folder>/dataset.json if present."""
json_path = build_annotation_json_path(folder)
if not os.path.exists(json_path):
return
abs_path = os.path.abspath(clip_path)
with open(json_path, "r", encoding="utf-8") as f:
try:
entries = json.load(f)
except (json.JSONDecodeError, ValueError):
return
entries = [e for e in entries if e.get("path") != abs_path]
with open(json_path, "w", encoding="utf-8") as f:
json.dump(entries, f, indent=2, ensure_ascii=False)
f.write("\n")
def upsert_clip_annotation(folder: str, clip_path: str, label: str) -> None:
"""Insert or update one entry in <folder>/dataset.json.
Each entry stores a path relative to *folder* and the sound label.
Matches on ``path``; if an entry for the same clip already exists it is
replaced (overwrite-export case). Nothing is written when *label* is
empty.
"""
if not label.strip():
return
os.makedirs(folder, exist_ok=True)
json_path = build_annotation_json_path(folder)
entries: list[dict] = []
if os.path.exists(json_path):
with open(json_path, "r", encoding="utf-8") as f:
try:
entries = json.load(f)
except (json.JSONDecodeError, ValueError):
entries = []
abs_path = os.path.abspath(clip_path)
entry: dict = {"path": abs_path, "label": label}
for i, e in enumerate(entries):
if e.get("path") == abs_path:
entries[i] = entry
break
else:
entries.append(entry)
with open(json_path, "w", encoding="utf-8") as f:
json.dump(entries, f, indent=2, ensure_ascii=False)
f.write("\n")
+242
View File
@@ -0,0 +1,242 @@
import sqlite3
import threading
from datetime import datetime, timezone
from pathlib import Path
from .paths import _log
class ProcessedDB:
_SCHEMA_VERSION = 3 # bump when schema changes
def __init__(self, db_path: str | None = None):
if db_path is None:
db_path = str(Path.home() / ".8cut.db")
self._path = db_path
self._lock = threading.Lock()
try:
self._con = sqlite3.connect(db_path, check_same_thread=False)
self._migrate()
self._enabled = True
_log(f"DB opened: {db_path}")
except Exception as e:
_log(f"DB unavailable: {e}")
self._con = None
self._enabled = False
def _migrate(self) -> None:
"""Create table if missing, then add any new columns for old DBs."""
cols = {
row[1]
for row in self._con.execute("PRAGMA table_info(processed)").fetchall()
}
if not cols:
# Fresh DB — create from scratch
self._con.execute(
"CREATE TABLE IF NOT EXISTS processed ("
" id INTEGER PRIMARY KEY AUTOINCREMENT,"
" filename TEXT NOT NULL,"
" start_time REAL NOT NULL,"
" output_path TEXT NOT NULL,"
" label TEXT NOT NULL DEFAULT '',"
" category TEXT NOT NULL DEFAULT '',"
" short_side INTEGER DEFAULT 512,"
" portrait_ratio TEXT NOT NULL DEFAULT '',"
" crop_center REAL NOT NULL DEFAULT 0.5,"
" format TEXT NOT NULL DEFAULT 'MP4',"
" clip_count INTEGER NOT NULL DEFAULT 3,"
" spread REAL NOT NULL DEFAULT 3.0,"
" profile TEXT NOT NULL DEFAULT 'default',"
" processed_at TEXT NOT NULL"
")"
)
else:
# Add missing columns to legacy tables
new_cols = {
"label": "TEXT NOT NULL DEFAULT ''",
"category": "TEXT NOT NULL DEFAULT ''",
"short_side": "INTEGER DEFAULT 512",
"portrait_ratio": "TEXT NOT NULL DEFAULT ''",
"crop_center": "REAL NOT NULL DEFAULT 0.5",
"format": "TEXT NOT NULL DEFAULT 'MP4'",
"clip_count": "INTEGER NOT NULL DEFAULT 3",
"spread": "REAL NOT NULL DEFAULT 3.0",
"profile": "TEXT NOT NULL DEFAULT 'default'",
}
for col, typedef in new_cols.items():
if col not in cols:
self._con.execute(
f"ALTER TABLE processed ADD COLUMN {col} {typedef}"
)
self._con.execute(
"CREATE INDEX IF NOT EXISTS idx_filename ON processed(filename)"
)
self._con.execute(
"CREATE TABLE IF NOT EXISTS hidden_files ("
" filename TEXT NOT NULL,"
" profile TEXT NOT NULL DEFAULT 'default',"
" PRIMARY KEY (filename, profile)"
")"
)
self._con.commit()
def add(self, filename: str, start_time: float, output_path: str,
label: str = "", category: str = "",
short_side: int | None = None, portrait_ratio: str = "",
crop_center: float = 0.5, fmt: str = "MP4",
clip_count: int = 3, spread: float = 3.0,
profile: str = "default") -> None:
if not self._enabled:
return
with self._lock:
self._con.execute(
"INSERT INTO processed"
" (filename, start_time, output_path, label, category,"
" short_side, portrait_ratio, crop_center, format,"
" clip_count, spread, profile, processed_at)"
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(filename, start_time, output_path, label, category,
short_side, portrait_ratio, crop_center, fmt,
clip_count, spread, profile,
datetime.now(timezone.utc).isoformat()),
)
self._con.commit()
def get_labels(self) -> list[str]:
"""Return distinct non-empty labels ordered by most recently used."""
if not self._enabled:
return []
rows = self._con.execute(
"SELECT DISTINCT label FROM processed"
" WHERE label != '' ORDER BY processed_at DESC"
).fetchall()
# Deduplicate while preserving order (DISTINCT on processed_at DESC
# may return duplicates if the same label was used multiple times).
seen: set[str] = set()
result = []
for (lbl,) in rows:
if lbl not in seen:
seen.add(lbl)
result.append(lbl)
return result
def get_by_output_path(self, output_path: str) -> dict | None:
"""Return config dict for an output_path, or None."""
if not self._enabled:
return None
cur = self._con.cursor()
cur.row_factory = sqlite3.Row
row = cur.execute(
"SELECT label, category, short_side, portrait_ratio, crop_center, format,"
" clip_count, spread"
" FROM processed WHERE output_path = ?",
(output_path,),
).fetchone()
return dict(row) if row else None
def delete_by_output_path(self, output_path: str) -> None:
if not self._enabled:
return
with self._lock:
self._con.execute("DELETE FROM processed WHERE output_path = ?", (output_path,))
self._con.commit()
def get_group(self, output_path: str) -> list[str]:
"""Return all output_paths sharing the same (filename, start_time) as *output_path*."""
if not self._enabled:
return []
row = self._con.execute(
"SELECT filename, start_time FROM processed WHERE output_path = ?",
(output_path,),
).fetchone()
if not row:
return []
rows = self._con.execute(
"SELECT output_path FROM processed"
" WHERE filename = ? AND start_time = ? ORDER BY output_path",
(row[0], row[1]),
).fetchall()
return [r[0] for r in rows]
def delete_group(self, output_path: str) -> list[str]:
"""Delete all rows sharing the same (filename, start_time) as *output_path*.
Returns list of deleted output_paths."""
if not self._enabled:
return []
with self._lock:
row = self._con.execute(
"SELECT filename, start_time FROM processed WHERE output_path = ?",
(output_path,),
).fetchone()
if not row:
return []
filename, start_time = row
paths = [r[0] for r in self._con.execute(
"SELECT output_path FROM processed WHERE filename = ? AND start_time = ?",
(filename, start_time),
).fetchall()]
self._con.execute(
"DELETE FROM processed WHERE filename = ? AND start_time = ?",
(filename, start_time),
)
self._con.commit()
return paths
def _get_markers_for(self, match: str, profile: str = "default") -> list[tuple[float, int, str]]:
rows = self._con.execute(
"SELECT start_time, output_path FROM processed"
" WHERE filename = ? AND profile = ? ORDER BY start_time",
(match, profile),
).fetchall()
# Deduplicate by start_time — batch exports share the same cursor.
seen_times: dict[float, tuple[float, int, str]] = {}
n = 0
for t, p in rows:
if t not in seen_times:
n += 1
seen_times[t] = (t, n, p)
return list(seen_times.values())
def get_markers(self, filename: str, profile: str = "default") -> list[tuple[float, int, str]]:
"""Return [(start_time, marker_number, output_path), ...] for exact
filename match, sorted by start_time. Empty list if no match."""
if not self._enabled:
return []
return self._get_markers_for(filename, profile)
def get_profiles(self) -> list[str]:
"""Return distinct profile names, ordered alphabetically."""
if not self._enabled:
return []
rows = self._con.execute(
"SELECT DISTINCT profile FROM processed ORDER BY profile"
).fetchall()
return [r[0] for r in rows]
def hide_file(self, filename: str, profile: str = "default") -> None:
if not self._enabled:
return
with self._lock:
self._con.execute(
"INSERT OR IGNORE INTO hidden_files (filename, profile) VALUES (?, ?)",
(filename, profile),
)
self._con.commit()
def unhide_file(self, filename: str, profile: str = "default") -> None:
if not self._enabled:
return
with self._lock:
self._con.execute(
"DELETE FROM hidden_files WHERE filename = ? AND profile = ?",
(filename, profile),
)
self._con.commit()
def get_hidden_files(self, profile: str = "default") -> set[str]:
if not self._enabled:
return set()
rows = self._con.execute(
"SELECT filename FROM hidden_files WHERE profile = ?", (profile,)
).fetchall()
return {r[0] for r in rows}
+127
View File
@@ -0,0 +1,127 @@
import os
import subprocess
import threading
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import Callable
from .ffmpeg import build_ffmpeg_command, build_audio_extract_command
from .paths import _log
class ExportRunner:
"""Run ffmpeg export jobs in a background thread pool.
Callbacks:
on_clip_done(path: str)
on_all_done()
on_error(msg: str)
"""
def __init__(
self,
input_path: str,
jobs: list[tuple[float, str, str | None, float]],
short_side: int | None = None,
image_sequence: bool = False,
max_workers: int | None = None,
encoder: str = "libx264",
on_clip_done: Callable[[str], None] | None = None,
on_all_done: Callable[[], None] | None = None,
on_error: Callable[[str], None] | None = None,
):
self._input = input_path
self._jobs = jobs
self._short_side = short_side
self._image_sequence = image_sequence
self._max_workers = max_workers
self._encoder = encoder
self._on_clip_done = on_clip_done
self._on_all_done = on_all_done
self._on_error = on_error
self._cancel = False
self._procs: list[subprocess.Popen] = []
self._procs_lock = threading.Lock()
self._thread: threading.Thread | None = None
def start(self):
self._thread = threading.Thread(target=self._run, daemon=True)
self._thread.start()
def cancel(self):
self._cancel = True
with self._procs_lock:
for proc in self._procs:
try:
proc.kill()
except OSError:
pass
def is_running(self) -> bool:
return self._thread is not None and self._thread.is_alive()
def _run_one(self, start: float, output: str,
portrait_ratio: str | None, crop_center: float) -> str:
if self._cancel:
raise RuntimeError("cancelled")
if self._image_sequence:
os.makedirs(output, exist_ok=True)
cmd = build_ffmpeg_command(
self._input, start, output,
short_side=self._short_side,
portrait_ratio=portrait_ratio,
crop_center=crop_center,
image_sequence=self._image_sequence,
encoder=self._encoder,
)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
with self._procs_lock:
self._procs.append(proc)
try:
_, stderr = proc.communicate(timeout=120)
except subprocess.TimeoutExpired:
proc.kill()
raise RuntimeError("ffmpeg timed out")
finally:
with self._procs_lock:
self._procs.remove(proc)
if self._cancel:
raise RuntimeError("cancelled")
if proc.returncode != 0:
msg = stderr.decode(errors='replace')[-500:] if stderr else "ffmpeg failed"
raise RuntimeError(msg)
if self._image_sequence:
audio_cmd = build_audio_extract_command(self._input, start, output)
audio_result = subprocess.run(audio_cmd, capture_output=True, text=True, timeout=60)
if audio_result.returncode != 0:
msg = (audio_result.stderr or "audio extraction failed")[-500:]
raise RuntimeError(msg)
return output
def _run(self):
cap = self._max_workers or (os.cpu_count() or 2)
workers = min(len(self._jobs), cap)
try:
with ThreadPoolExecutor(max_workers=workers) as pool:
futures = {
pool.submit(self._run_one, s, o, pr, cc): o
for s, o, pr, cc in self._jobs
}
for fut in as_completed(futures):
if self._cancel:
break
try:
path = fut.result()
if self._on_clip_done:
self._on_clip_done(path)
except Exception as e:
if "cancelled" not in str(e) and self._on_error:
self._on_error(str(e))
return
except Exception as e:
if self._on_error:
self._on_error(str(e))
return
if self._cancel:
return
if self._on_all_done:
self._on_all_done()
+160
View File
@@ -0,0 +1,160 @@
import os
import re
import subprocess
from .paths import _bin, _log
_RATIOS: dict[str, tuple[int, int]] = {
"9:16": (9, 16),
"4:5": (4, 5),
"1:1": (1, 1),
}
def _portrait_crop_filter(ratio: str, crop_center: float) -> str:
"""Return an ffmpeg crop= filter expression for the given portrait ratio.
Uses ffmpeg expression syntax so source dimensions are resolved at runtime.
Commas inside min()/max() are escaped with \\, to prevent ffmpeg's
filtergraph parser from treating them as filter-chain separators.
"""
num, den = _RATIOS[ratio]
cw = f"ih*{num}/{den}"
x = f"max(0\\,min((iw-{cw})*{crop_center}\\,iw-{cw}))"
return f"crop={cw}:ih:{x}:0"
def resolve_keyframe(
keyframes: list[tuple[float, float, str | None, bool, bool]],
t: float,
tolerance: float = 0.05,
) -> tuple[float, float, str | None, bool, bool] | None:
"""Return the latest keyframe at or before *t*, or None."""
result = None
for kf in keyframes:
if kf[0] <= t + tolerance:
result = kf
else:
break
return result
def apply_keyframes_to_jobs(
jobs: list[tuple[float, str, str | None, float]],
keyframes: list[tuple[float, float, str | None, bool, bool]],
base_center: float,
base_ratio: str | None,
base_rand_p: bool,
base_rand_s: bool,
) -> list[tuple[float, str, str | None, float, bool, bool]]:
"""Resolve each job's crop state from keyframes, returning widened tuples.
Returns list of (start, path, ratio, center, rand_portrait, rand_square).
"""
result = []
for s, o, _r, _c in jobs:
kf = resolve_keyframe(keyframes, s)
if kf is not None:
_, center, ratio, rp, rs = kf
else:
center, ratio, rp, rs = base_center, base_ratio, base_rand_p, base_rand_s
result.append((s, o, ratio, center, rp, rs))
return result
def build_ffmpeg_command(
input_path: str, start: float, output_path: str,
short_side: int | None = None,
portrait_ratio: str | None = None,
crop_center: float = 0.5,
image_sequence: bool = False,
encoder: str = "libx264",
) -> list[str]:
# -ss before -i: fast input-seeking. Safe here because we always re-encode,
# so there is no keyframe-alignment issue from pre-input seek.
# Image sequences always use libwebp, so skip HW encoder setup.
use_hw_vaapi = encoder == "h264_vaapi" and not image_sequence
cmd = [_bin("ffmpeg"), "-y"]
# VAAPI needs a device for hardware context.
if use_hw_vaapi:
cmd += ["-hwaccel", "vaapi", "-hwaccel_output_format", "vaapi",
"-vaapi_device", "/dev/dri/renderD128"]
cmd += [
"-threads", "0",
"-ss", str(start),
"-i", input_path,
"-t", "8",
]
filters: list[str] = []
if portrait_ratio is not None:
filters.append(_portrait_crop_filter(portrait_ratio, crop_center))
if short_side is not None:
# Scale so the shorter dimension equals short_side.
filters.append(
f"scale='if(lt(iw,ih),{short_side},-2)':'if(lt(iw,ih),-2,{short_side})':flags=lanczos"
)
# VAAPI: decoded frames are GPU surfaces. CPU filters need hwdownload first.
if use_hw_vaapi:
if filters:
filters.insert(0, "hwdownload")
filters.insert(1, "format=nv12")
filters.append("format=nv12")
filters.append("hwupload")
if filters:
cmd += ["-vf", ",".join(filters)]
if image_sequence:
cmd += [
"-an",
"-c:v", "libwebp",
"-quality", "92",
"-compression_level", "1",
os.path.join(output_path, "frame_%04d.webp"),
]
else:
cmd += ["-c:v", encoder, "-c:a", "pcm_s16le", output_path]
return cmd
def build_audio_extract_command(input_path: str, start: float, sequence_dir: str) -> list[str]:
"""Return an ffmpeg command that extracts audio to <sequence_dir>.wav."""
audio_path = sequence_dir + ".wav"
return [
_bin("ffmpeg"), "-y",
"-ss", str(start),
"-i", input_path,
"-t", "8",
"-vn",
"-c:a", "pcm_s16le",
audio_path,
]
def detect_hw_encoders() -> list[str]:
"""Probe ffmpeg for available H.264 hardware encoders."""
_HW_ENCODERS = ["h264_nvenc", "h264_vaapi", "h264_qsv", "h264_amf", "h264_videotoolbox"]
try:
result = subprocess.run(
[_bin("ffmpeg"), "-hide_banner", "-encoders"],
capture_output=True, text=True, timeout=5,
)
if result.returncode != 0:
return []
output = result.stdout
except Exception:
return []
available = []
for enc in _HW_ENCODERS:
if re.search(rf'\b{enc}\b', output):
available.append(enc)
if available:
_log(f"HW encoders detected: {', '.join(available)}")
else:
_log("No HW encoders detected — GPU export unavailable")
return available
+44
View File
@@ -0,0 +1,44 @@
import os
import sys
from datetime import datetime
from pathlib import Path
def _frozen_path() -> Path:
if getattr(sys, "frozen", False):
return Path(sys._MEIPASS)
return Path(__file__).resolve().parent.parent
def _bin(name: str) -> str:
"""Resolve a binary name (e.g. 'ffmpeg') to its full path in frozen builds."""
p = _frozen_path() / name
if p.exists():
return str(p)
return name # fall back to PATH
def _log(*args) -> None:
"""Print a timestamped log line to stderr."""
ts = datetime.now().strftime("%H:%M:%S")
print(f"[8-cut {ts}]", *args, file=sys.stderr)
def build_export_path(folder: str, basename: str, counter: int, sub: int | None = None) -> str:
group = f"{basename}_{counter:03d}"
name = f"{group}_{sub}" if sub is not None else group
return os.path.join(folder, group, name + ".mp4")
def build_sequence_dir(folder: str, basename: str, counter: int, sub: int | None = None) -> str:
group = f"{basename}_{counter:03d}"
name = f"{group}_{sub}" if sub is not None else group
return os.path.join(folder, group, name)
def format_time(seconds: float) -> str:
m = int(seconds // 60)
# Floor-truncate to 1 dp (not round) — prevents "X:60.0" rollover when
# seconds is e.g. 59.95.
s = int(seconds % 60 * 10) / 10
return f"{m}:{s:04.1f}"
+104
View File
@@ -0,0 +1,104 @@
import os
import subprocess
import tempfile
from .paths import _bin, _log
_yolo_model = None
def _get_yolo():
"""Lazy-load YOLOv8-nano. Returns None if ultralytics is not installed."""
global _yolo_model
if _yolo_model is None:
try:
from ultralytics import YOLO
_yolo_model = YOLO("yolov8n.pt")
_log("YOLO model loaded")
except ImportError:
_log("ultralytics not installed — tracking disabled")
return None
except Exception as e:
_log(f"YOLO load failed: {e}")
return None
return _yolo_model
def extract_frame_cv(video_path: str, time: float):
"""Extract a single frame as a numpy array (BGR) via ffmpeg -> temp PNG -> cv2."""
try:
import cv2
import numpy as np
except ImportError:
return None
fd, tmp = tempfile.mkstemp(suffix=".png")
os.close(fd)
try:
cmd = [_bin("ffmpeg"), "-y", "-ss", str(time), "-i", video_path,
"-frames:v", "1", tmp]
result = subprocess.run(cmd, capture_output=True, timeout=10)
if result.returncode != 0:
return None
return cv2.imread(tmp)
except Exception:
return None
finally:
if os.path.exists(tmp):
os.unlink(tmp)
def detect_subject_center(
video_path: str, time: float, target_cls: int | None, last_x: float, last_y: float,
) -> tuple[int | None, float, float] | None:
"""Detect objects at *time* and return (class_id, norm_x, norm_y) of the
best match to (target_cls, last_x, last_y). Returns None on failure."""
model = _get_yolo()
if model is None:
return None
frame = extract_frame_cv(video_path, time)
if frame is None:
return None
results = model(frame, verbose=False)
if not results or len(results[0].boxes) == 0:
return None
h, w = frame.shape[:2]
dets = []
for box in results[0].boxes:
x1, y1, x2, y2 = box.xyxy[0].tolist()
cls = int(box.cls[0])
cx = (x1 + x2) / 2 / w
cy = (y1 + y2) / 2 / h
dets.append((cls, cx, cy))
# Prefer same class, nearest to last known position.
def score(d):
cls_penalty = 0 if (target_cls is None or d[0] == target_cls) else 1.0
dist = (d[1] - last_x) ** 2 + (d[2] - last_y) ** 2
return cls_penalty + dist
best = min(dets, key=score)
return best
def track_centers_for_jobs(
video_path: str, cursor: float, crop_center: float,
starts: list[float],
) -> list[float]:
"""Run detection at the cursor (to identify the target) then at each start
time. Returns a list of horizontal crop centers (one per start)."""
ref = detect_subject_center(video_path, cursor, None, crop_center, 0.5)
if ref is None:
_log("Tracking: no detection at cursor, using fixed center")
return [crop_center] * len(starts)
target_cls, last_x, last_y = ref
_log(f"Tracking: target class={target_cls} at ({last_x:.2f}, {last_y:.2f})")
centers = []
for t in starts:
det = detect_subject_center(video_path, t, target_cls, last_x, last_y)
if det is not None:
_, cx, cy = det
_log(f" t={t:.2f}s → center={cx:.3f}")
centers.append(cx)
last_x, last_y = cx, cy
else:
_log(f" t={t:.2f}s → lost, reusing {last_x:.3f}")
centers.append(last_x)
return centers
+24
View File
@@ -0,0 +1,24 @@
services:
8cut:
build: .
ports:
- "8000:8000"
volumes:
- /path/to/videos:/videos:ro
- /path/to/exports:/exports
- 8cut-data:/data
environment:
MEDIA_DIRS: /videos
EXPORT_DIR: /exports
DB_PATH: /data/8cut.db
CACHE_DIR: /data/cache
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
volumes:
8cut-data:
@@ -0,0 +1,51 @@
# Keyframe crop modes design
## Problem
Currently, crop keyframes only store position (time, center). The random portrait and random square checkboxes apply globally to the entire batch. When a batch spans a scene change (e.g. wide landscape to close-up), portrait crop may only make sense for part of the span.
## Solution
Extend keyframes to snapshot the full crop state — position, ratio, and random crop flags — so each sub-clip in a batch inherits crop settings from the latest keyframe at or before its start time.
## Keyframe data
Expand from `(time, center)` to `(time, center, ratio, rand_portrait, rand_square)`:
- `time` (float) — absolute time in seconds
- `center` (float) — horizontal crop position, 0.0 to 1.0
- `ratio` (str | None) — portrait combo value: `None`, `"9:16"`, `"4:5"`, or `"1:1"`
- `rand_portrait` (bool) — random portrait checkbox state
- `rand_square` (bool) — random square checkbox state
## Setting keyframes
Same interaction as today: click the crop bar while in lock mode. The click now snapshots the current center, portrait combo selection, rand_portrait checkbox, and rand_square checkbox into the keyframe.
## Export application
For each sub-clip job:
1. Find the latest keyframe where `kt <= start_time + 0.05`.
2. Apply its `center` and `ratio` to the job.
3. Collect the effective `rand_portrait` and `rand_square` flags.
4. After all keyframes are resolved, apply random crop selection only to sub-clips whose effective flags are set. The random selection (`n_random = max(1, eligible_count // 3)`) operates within each flag group independently.
When no keyframes exist, behavior is unchanged (global checkboxes apply to all clips).
## Timeline diamond colors
Each keyframe diamond on the timeline is color-coded by its random crop flags:
- No random flags — gold (current color, `#ffb400`)
- Portrait only — red (`QColor(220, 60, 60)`)
- Square only — blue (`QColor(60, 180, 220)`)
- Both — split diamond: left half red, right half blue
## Playback preview in lock mode
When scrubbing in lock mode, `_on_seek_changed` already updates the crop bar preview from keyframes. This extends to also update the portrait combo and random checkboxes to reflect the effective state at the current playback position, so the user sees what each region's settings are.
## Clearing
Toggling lock off clears all keyframes (existing behavior, unchanged).
@@ -0,0 +1,634 @@
# Keyframe Crop Modes Implementation Plan
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
**Goal:** Extend crop keyframes to snapshot ratio and random crop flags, so different sub-clips in a batch inherit different crop settings based on timeline position.
**Architecture:** Widen the keyframe tuple from `(time, center)` to `(time, center, ratio, rand_portrait, rand_square)`. All existing keyframe code paths (set, delete, clear, render, apply-at-export, preview-on-scrub) are updated to carry and use the new fields. Diamond rendering on the timeline uses color to indicate which random flags are set.
**Tech Stack:** Python, PyQt6 (QPainter for diamonds)
---
### Task 1: Add a helper to resolve the effective keyframe at a given time
The keyframe lookup pattern (iterate sorted list, take latest where `kt <= t + 0.05`) is repeated 3 times in main.py. Extract it as a pure function so we can test it and reuse it cleanly with the new wider tuple.
**Files:**
- Modify: `main.py:48-53` (module-level functions area)
- Test: `tests/test_utils.py`
**Step 1: Write the failing tests**
Add to `tests/test_utils.py`:
```python
from main import resolve_keyframe
def test_resolve_keyframe_empty():
assert resolve_keyframe([], 5.0) is None
def test_resolve_keyframe_before_first():
kfs = [(3.0, 0.5, None, False, False)]
assert resolve_keyframe(kfs, 1.0) is None
def test_resolve_keyframe_exact():
kfs = [(2.0, 0.3, "9:16", True, False)]
assert resolve_keyframe(kfs, 2.0) == (2.0, 0.3, "9:16", True, False)
def test_resolve_keyframe_between():
kfs = [
(1.0, 0.2, None, False, False),
(5.0, 0.8, "1:1", False, True),
]
assert resolve_keyframe(kfs, 3.0) == (1.0, 0.2, None, False, False)
def test_resolve_keyframe_after_last():
kfs = [
(1.0, 0.2, None, False, False),
(5.0, 0.8, "1:1", False, True),
]
assert resolve_keyframe(kfs, 10.0) == (5.0, 0.8, "1:1", False, True)
def test_resolve_keyframe_tolerance():
kfs = [(4.0, 0.5, None, True, True)]
# 4.0 <= 3.96 + 0.05 = 4.01, so it should match
assert resolve_keyframe(kfs, 3.96) == (4.0, 0.5, None, True, True)
```
**Step 2: Run tests to verify they fail**
Run: `pytest tests/test_utils.py -k resolve_keyframe -v`
Expected: FAIL (ImportError — function does not exist yet)
**Step 3: Write the implementation**
Add to `main.py` after the `format_time` function (around line 53):
```python
def resolve_keyframe(
keyframes: list[tuple[float, float, str | None, bool, bool]],
t: float,
tolerance: float = 0.05,
) -> tuple[float, float, str | None, bool, bool] | None:
"""Return the latest keyframe at or before *t*, or None."""
result = None
for kf in keyframes:
if kf[0] <= t + tolerance:
result = kf
else:
break
return result
```
**Step 4: Run tests to verify they pass**
Run: `pytest tests/test_utils.py -k resolve_keyframe -v`
Expected: 6 PASS
**Step 5: Commit**
```bash
git add main.py tests/test_utils.py
git commit -m "feat: add resolve_keyframe helper for widened keyframe tuples"
```
---
### Task 2: Widen keyframe tuple and update storage
Change `_crop_keyframes` from `list[tuple[float, float]]` to `list[tuple[float, float, str | None, bool, bool]]` in both `TimelineWidget` and `MainWindow`. Update `set_crop_keyframes` signature.
**Files:**
- Modify: `main.py:735` (TimelineWidget._crop_keyframes)
- Modify: `main.py:786-787` (TimelineWidget.set_crop_keyframes)
- Modify: `main.py:1755` (MainWindow._crop_keyframes)
**Step 1: Update TimelineWidget**
At line 735, change:
```python
self._crop_keyframes: list[tuple[float, float]] = [] # [(time, center)]
```
to:
```python
self._crop_keyframes: list[tuple[float, float, str | None, bool, bool]] = []
```
At lines 786-787, change:
```python
def set_crop_keyframes(self, kfs: list[tuple[float, float]]) -> None:
self._crop_keyframes = kfs
```
to:
```python
def set_crop_keyframes(self, kfs: list[tuple[float, float, str | None, bool, bool]]) -> None:
self._crop_keyframes = kfs
```
**Step 2: Update MainWindow**
At line 1755, change:
```python
self._crop_keyframes: list[tuple[float, float]] = [] # [(time, center), ...] sorted
```
to:
```python
self._crop_keyframes: list[tuple[float, float, str | None, bool, bool]] = [] # sorted by time
```
**Step 3: Run existing tests**
Run: `pytest tests/ -v`
Expected: All 46 + 6 new = 52 PASS (no existing tests touch keyframes directly)
**Step 4: Commit**
```bash
git add main.py
git commit -m "refactor: widen keyframe tuple to carry ratio and random flags"
```
---
### Task 3: Update keyframe creation to snapshot crop state
When the user clicks the crop bar in lock mode, snapshot the current ratio, rand_portrait, and rand_square into the keyframe.
**Files:**
- Modify: `main.py:2519-2538` (_on_crop_click lock-mode branch)
**Step 1: Update the keyframe creation code**
At lines 2525-2532, change:
```python
self._crop_keyframes = [
(t, c) for t, c in self._crop_keyframes
if abs(t - play_t) > 0.05
]
self._crop_keyframes.append((play_t, frac))
self._crop_keyframes.sort()
self._timeline.set_crop_keyframes(self._crop_keyframes)
_log(f"Crop keyframe: t={play_t:.2f}s center={frac:.3f} ({len(self._crop_keyframes)} total)")
```
to:
```python
ratio_text = self._cmb_portrait.currentText()
kf_ratio = None if ratio_text == "Off" else ratio_text
kf_rand_p = self._chk_rand_portrait.isChecked()
kf_rand_s = self._chk_rand_square.isChecked()
self._crop_keyframes = [
kf for kf in self._crop_keyframes
if abs(kf[0] - play_t) > 0.05
]
self._crop_keyframes.append((play_t, frac, kf_ratio, kf_rand_p, kf_rand_s))
self._crop_keyframes.sort()
self._timeline.set_crop_keyframes(self._crop_keyframes)
_log(f"Crop keyframe: t={play_t:.2f}s center={frac:.3f} ratio={kf_ratio} rp={kf_rand_p} rs={kf_rand_s} ({len(self._crop_keyframes)} total)")
```
**Step 2: Update keyframe deletion filter**
At lines 2356-2357, change:
```python
self._crop_keyframes = [
(t, c) for t, c in self._crop_keyframes
if abs(t - time) > 0.05
]
```
to:
```python
self._crop_keyframes = [
kf for kf in self._crop_keyframes
if abs(kf[0] - time) > 0.05
]
```
**Step 3: Run existing tests**
Run: `pytest tests/ -v`
Expected: All 52 PASS
**Step 4: Commit**
```bash
git add main.py
git commit -m "feat: snapshot ratio and random flags into crop keyframes"
```
---
### Task 4: Update export to apply full keyframe state
Replace the keyframe application loop and random crop logic in `_on_export` to use the new fields.
**Files:**
- Modify: `main.py:2754-2782` (keyframe application + random crop logic in _on_export)
- Test: `tests/test_utils.py`
**Step 1: Write a test for the export keyframe resolution logic**
Add to `tests/test_utils.py`:
```python
from main import apply_keyframes_to_jobs
def test_apply_keyframes_no_keyframes():
jobs = [(0.0, "/out/a", None, 0.5), (3.0, "/out/b", None, 0.5)]
result = apply_keyframes_to_jobs(jobs, [], base_center=0.5, base_ratio=None,
base_rand_p=True, base_rand_s=False)
# No keyframes: jobs get base values; rand flags come from base
assert result == [
(0.0, "/out/a", None, 0.5, True, False),
(3.0, "/out/b", None, 0.5, True, False),
]
def test_apply_keyframes_with_keyframes():
kfs = [
(0.0, 0.3, "9:16", True, False),
(4.0, 0.7, None, False, True),
]
jobs = [
(0.0, "/out/a", None, 0.5),
(3.0, "/out/b", None, 0.5),
(6.0, "/out/c", None, 0.5),
]
result = apply_keyframes_to_jobs(jobs, kfs, base_center=0.5, base_ratio=None,
base_rand_p=False, base_rand_s=False)
assert result == [
(0.0, "/out/a", "9:16", 0.3, True, False),
(3.0, "/out/b", "9:16", 0.3, True, False),
(6.0, "/out/c", None, 0.7, False, True),
]
def test_apply_keyframes_before_first_uses_base():
kfs = [(5.0, 0.8, "1:1", False, True)]
jobs = [(1.0, "/out/a", None, 0.5)]
result = apply_keyframes_to_jobs(jobs, kfs, base_center=0.5, base_ratio="4:5",
base_rand_p=True, base_rand_s=False)
assert result == [(1.0, "/out/a", "4:5", 0.5, True, False)]
```
**Step 2: Run tests to verify they fail**
Run: `pytest tests/test_utils.py -k apply_keyframes -v`
Expected: FAIL (ImportError)
**Step 3: Write the apply_keyframes_to_jobs function**
Add to `main.py` after `resolve_keyframe`:
```python
def apply_keyframes_to_jobs(
jobs: list[tuple[float, str, str | None, float]],
keyframes: list[tuple[float, float, str | None, bool, bool]],
base_center: float,
base_ratio: str | None,
base_rand_p: bool,
base_rand_s: bool,
) -> list[tuple[float, str, str | None, float, bool, bool]]:
"""Resolve each job's crop state from keyframes, returning widened tuples.
Returns list of (start, path, ratio, center, rand_portrait, rand_square).
"""
result = []
for s, o, _r, _c in jobs:
kf = resolve_keyframe(keyframes, s)
if kf is not None:
_, center, ratio, rp, rs = kf
else:
center, ratio, rp, rs = base_center, base_ratio, base_rand_p, base_rand_s
result.append((s, o, ratio, center, rp, rs))
return result
```
**Step 4: Run tests to verify they pass**
Run: `pytest tests/test_utils.py -k apply_keyframes -v`
Expected: 3 PASS
**Step 5: Update _on_export to use the new functions**
Replace lines 2754-2782 (the keyframe application block + random crop block) with:
```python
# Apply crop keyframes (or fall back to base state).
rand_portrait = self._chk_rand_portrait.isChecked()
rand_square = self._chk_rand_square.isChecked()
widened = apply_keyframes_to_jobs(
jobs, self._crop_keyframes,
base_center=base_center, base_ratio=base_ratio,
base_rand_p=rand_portrait, base_rand_s=rand_square,
)
# Random crop: for each clip whose effective flags are set,
# ~1 in 3 gets a random ratio applied.
final_jobs = []
# Collect indices eligible for random crop, grouped by flag combo.
portrait_eligible = [i for i, w in enumerate(widened) if w[4]]
square_eligible = [i for i, w in enumerate(widened) if w[5]]
rand_indices: set[int] = set()
if portrait_eligible and n_clips > 1:
n = max(1, len(portrait_eligible) // 3)
rand_indices.update(random.sample(portrait_eligible, min(n, len(portrait_eligible))))
if square_eligible and n_clips > 1:
n = max(1, len(square_eligible) // 3)
rand_indices.update(random.sample(square_eligible, min(n, len(square_eligible))))
for i, (s, o, ratio, center, rp, rs) in enumerate(widened):
if i in rand_indices:
pool = []
if rp:
pool.append("9:16")
if rs:
pool.append("1:1")
if pool:
ratio = random.choice(pool)
jobs.append((s, o, ratio, center))
# Replace jobs with the resolved list.
jobs = jobs[n_clips:] # drop the original entries, keep the new ones
```
Note: `jobs` was built with `n_clips` entries in the loop above. We append resolved entries and then slice off the originals.
Actually, a cleaner rewrite of the tail — replace the entire block from the keyframe comment through the random crop block with:
```python
# Apply crop keyframes (or fall back to base state).
rand_portrait = self._chk_rand_portrait.isChecked()
rand_square = self._chk_rand_square.isChecked()
widened = apply_keyframes_to_jobs(
jobs, self._crop_keyframes,
base_center=base_center, base_ratio=base_ratio,
base_rand_p=rand_portrait, base_rand_s=rand_square,
)
# Random crop: eligible clips (per their keyframe flags) have
# ~1 in 3 chance of getting a random ratio applied.
portrait_eligible = [i for i, w in enumerate(widened) if w[4]]
square_eligible = [i for i, w in enumerate(widened) if w[5]]
rand_indices: dict[int, list[str]] = {}
if portrait_eligible and n_clips > 1:
n = max(1, len(portrait_eligible) // 3)
for i in random.sample(portrait_eligible, min(n, len(portrait_eligible))):
rand_indices.setdefault(i, []).append("9:16")
if square_eligible and n_clips > 1:
n = max(1, len(square_eligible) // 3)
for i in random.sample(square_eligible, min(n, len(square_eligible))):
rand_indices.setdefault(i, []).append("1:1")
jobs = []
for i, (s, o, ratio, center, _rp, _rs) in enumerate(widened):
if i in rand_indices:
ratio = random.choice(rand_indices[i])
jobs.append((s, o, ratio, center))
```
**Step 6: Run all tests**
Run: `pytest tests/ -v`
Expected: All PASS
**Step 7: Commit**
```bash
git add main.py tests/test_utils.py
git commit -m "feat: apply keyframe crop modes during export"
```
---
### Task 5: Update diamond rendering with color coding
Color-code timeline keyframe diamonds based on their random flags.
**Files:**
- Modify: `main.py:898-910` (TimelineWidget.paintEvent keyframe diamond section)
**Step 1: Replace the diamond rendering block**
Replace lines 898-910:
```python
# ── crop keyframe diamonds ────────────────────────────────────
if self._crop_keyframes and self._duration > 0:
for (kt, _kc) in self._crop_keyframes:
kx = int(kt / self._duration * w)
d = 4 # half-size of diamond
ky = h - d - 2 # near bottom of track
diamond = QPolygon([
QPoint(kx, ky - d), QPoint(kx + d, ky),
QPoint(kx, ky + d), QPoint(kx - d, ky),
])
p.setBrush(QColor(255, 180, 0))
p.setPen(Qt.PenStyle.NoPen)
p.drawPolygon(diamond)
```
with:
```python
# ── crop keyframe diamonds ────────────────────────────────────
if self._crop_keyframes and self._duration > 0:
_KF_GOLD = QColor(255, 180, 0)
_KF_RED = QColor(220, 60, 60)
_KF_BLUE = QColor(60, 180, 220)
for kf in self._crop_keyframes:
kt = kf[0]
rp = kf[3] if len(kf) > 3 else False
rs = kf[4] if len(kf) > 4 else False
kx = int(kt / self._duration * w)
d = 4 # half-size of diamond
ky = h - d - 2 # near bottom of track
if rp and rs:
# Split diamond: left half red, right half blue
left = QPolygon([
QPoint(kx, ky - d), QPoint(kx, ky + d),
QPoint(kx - d, ky),
])
right = QPolygon([
QPoint(kx, ky - d), QPoint(kx + d, ky),
QPoint(kx, ky + d),
])
p.setPen(Qt.PenStyle.NoPen)
p.setBrush(_KF_RED)
p.drawPolygon(left)
p.setBrush(_KF_BLUE)
p.drawPolygon(right)
else:
diamond = QPolygon([
QPoint(kx, ky - d), QPoint(kx + d, ky),
QPoint(kx, ky + d), QPoint(kx - d, ky),
])
if rp:
color = _KF_RED
elif rs:
color = _KF_BLUE
else:
color = _KF_GOLD
p.setPen(Qt.PenStyle.NoPen)
p.setBrush(color)
p.drawPolygon(diamond)
```
**Step 2: Update the context menu keyframe hit detection**
At line 980, change:
```python
for (kt, _kc) in self._crop_keyframes:
```
to:
```python
for kf in self._crop_keyframes:
kt = kf[0]
```
And remove the `_kc` reference — use `kf[0]` for `kt` only. The rest of the hit-detection logic stays the same.
**Step 3: Run all tests**
Run: `pytest tests/ -v`
Expected: All PASS
**Step 4: Manual test**
Launch the app, load a video, enable lock mode, set keyframes with different combinations of random portrait/square. Verify:
- Gold diamond when no random flags set
- Red diamond when only portrait
- Blue diamond when only square
- Split red/blue when both
**Step 5: Commit**
```bash
git add main.py
git commit -m "feat: color-code keyframe diamonds by crop mode"
```
---
### Task 6: Update lock-mode scrub preview
When scrubbing in lock mode, update the crop bar, overlay, and (visually) the random checkboxes to reflect the effective keyframe state at the playback position.
**Files:**
- Modify: `main.py:2605-2621` (_on_seek_changed)
**Step 1: Replace the keyframe preview block**
Replace lines 2610-2621:
```python
if self._crop_keyframes:
center = self._crop_center
for kt, kc in self._crop_keyframes:
if kt <= t + 0.05:
center = kc
else:
break
self._crop_bar.set_crop_center(center)
ratio = self._cmb_portrait.currentText()
if ratio != "Off":
self._mpv.set_crop_overlay(_RATIOS[ratio], center)
```
with:
```python
if self._crop_keyframes:
kf = resolve_keyframe(self._crop_keyframes, t)
if kf is not None:
_, center, ratio, rp, rs = kf
self._crop_bar.set_crop_center(center)
if ratio is not None:
self._mpv.set_crop_overlay(_RATIOS[ratio], center)
else:
self._update_rand_overlays()
```
**Step 2: Run all tests**
Run: `pytest tests/ -v`
Expected: All PASS
**Step 3: Commit**
```bash
git add main.py
git commit -m "feat: preview effective keyframe crop state during lock-mode scrub"
```
---
### Task 7: Update overwrite-mode keyframe application
The overwrite path (lines 2727-2738) also builds jobs. It doesn't currently apply keyframes, but should for consistency.
**Files:**
- Modify: `main.py:2727-2738` (overwrite branch in _on_export)
**Step 1: Check and update**
After the overwrite jobs are built, apply the same `apply_keyframes_to_jobs` logic if keyframes exist. The overwrite branch builds `jobs` as `(start, path, base_ratio, base_center)` — same shape as the normal path.
Add after line 2738 (`self._overwrite_group = []`):
```python
rand_portrait = self._chk_rand_portrait.isChecked()
rand_square = self._chk_rand_square.isChecked()
if self._crop_keyframes:
widened = apply_keyframes_to_jobs(
jobs, self._crop_keyframes,
base_center=base_center, base_ratio=base_ratio,
base_rand_p=rand_portrait, base_rand_s=rand_square,
)
jobs = [(s, o, r, c) for s, o, r, c, _rp, _rs in widened]
```
**Step 2: Run all tests**
Run: `pytest tests/ -v`
Expected: All PASS
**Step 3: Commit**
```bash
git add main.py
git commit -m "feat: apply keyframe crop modes in overwrite exports too"
```
---
### Task 8: Update import in test file and final validation
**Files:**
- Modify: `tests/test_utils.py:2` (import line)
**Step 1: Update imports**
At line 2, add the new functions to the import:
```python
from main import build_export_path, format_time, build_ffmpeg_command, build_sequence_dir, build_audio_extract_command, build_annotation_json_path, upsert_clip_annotation, resolve_keyframe, apply_keyframes_to_jobs
```
(This should already be done incrementally in Tasks 1 and 4, but verify it's correct.)
**Step 2: Run full test suite**
Run: `pytest tests/ -v`
Expected: All 55 tests PASS (46 original + 6 resolve_keyframe + 3 apply_keyframes)
**Step 3: Manual integration test**
1. Launch `python main.py`, load a video
2. Enable lock mode (G or click lock button)
3. Scrub to a position, enable "1 random portrait", click crop bar → red diamond appears
4. Scrub forward, disable portrait, enable "1 random square", click crop bar → blue diamond appears
5. Scrub forward, enable both, click crop bar → split red/blue diamond
6. Set clip count to 6+, spread to 2s, export
7. Verify that sub-clips falling in each keyframe region get the correct random crop behavior
8. Right-click a diamond to delete it — verify it disappears
**Step 4: Commit**
```bash
git add tests/test_utils.py
git commit -m "test: verify imports for keyframe crop mode helpers"
```
+148
View File
@@ -0,0 +1,148 @@
# 8-cut Client Design
## Goal
Build a Tauri + Svelte desktop client that connects to the 8-cut server API for remote video editing. Full feature parity with the Qt app. Targets Linux first, then Mac.
## Architecture
```
Tauri app (Rust shell + Svelte webview)
├── mpv sidecar (bundled binary)
│ ├── plays video: http://server/api/stream/{path}?quality=low
│ ├── plays audio: http://server/api/audio/{path}
│ └── controlled via JSON IPC socket
├── Svelte UI
│ ├── File browser
│ ├── Canvas timeline (markers, cursor, play region)
│ ├── Canvas crop overlay
│ ├── Export controls + WebSocket progress
│ └── Settings panel (profile, subprofiles, quality)
└── Rust backend
├── Spawn/manage mpv process + IPC
├── Proxy server API calls (avoid CORS)
└── Tauri commands exposed to Svelte frontend
```
## Playback
mpv runs as a sidecar process, controlled via JSON IPC socket. Two streams:
- Video: `http://server/api/stream/{path}?root={root}&quality={quality}` (transcoded, no audio)
- Audio: `http://server/api/audio/{path}?root={root}` (full quality WAV)
mpv's `--audio-file=` flag syncs both streams with frame-accurate seeking.
Quality presets: potato (480p), low (720p), medium (1080p), high (original).
## Features
### File management
- Browse server video roots (`GET /api/roots`, `GET /api/files`)
- Hide/unhide files per profile (`POST/DELETE /api/hidden/{filename}`)
- Sort by name/size, filter hidden
### Playback
- Play/pause/resume from pause point
- AB-loop with current spread/clips settings
- Play region adapts to spread changes without restarting
- Quality selector
### Timeline (Canvas)
- Cursor position, markers, play position indicator
- Click to seek, drag cursor
- Lock mode: cursor locked to marker, double-click jumps to end of clip span
- Autoclip: when paused, auto-adjust clip count to fit pause position
### Crop & keyframes
- Portrait ratio selector (9:16, 4:5, 1:1, off)
- Crop center slider with live canvas overlay
- Crop keyframes at arbitrary timeline positions
- Subject tracking (triggered server-side)
- Random portrait/square toggles
### Export
- Configurable: clips, spread, short side, format (MP4/WebP sequence)
- Label + category annotation
- Encoder selection (libx264 / h264_nvenc)
- Subprofiles with folder suffix routing
- Number keys 1-9 for subprofile quick export, E for main
- WebSocket progress (`WS /ws/export`), per-clip completion
- Delete/re-export from marker context menu
### Profiles
- Profile switcher, markers reload per profile
- Subprofile management (add/remove)
### Settings
- Server URL (configurable)
- Default quality preset
- All settings persisted client-side via Tauri store
## Server API endpoints used
```
GET /api/roots
GET /api/files?root={root}
GET /api/video/{path}?root={root}
GET /api/stream/{path}?root={root}&quality={quality}
GET /api/audio/{path}?root={root}
GET /api/cache/status/{path}?root={root}
GET /api/markers/{filename}?profile={profile}
GET /api/profiles
GET /api/labels
POST /api/export
GET /api/export/{job_id}
DELETE /api/export?output_path={path}
POST /api/hidden/{filename}?profile={profile}
DELETE /api/hidden/{filename}?profile={profile}
GET /api/hidden?profile={profile}
WS /ws/export
```
## Project structure
```
client/
├── src-tauri/
│ ├── src/
│ │ ├── main.rs (Tauri entry, app setup)
│ │ ├── mpv.rs (mpv sidecar spawn + IPC)
│ │ ├── commands.rs (Tauri commands for Svelte)
│ │ └── lib.rs
│ ├── Cargo.toml
│ └── tauri.conf.json
├── src/
│ ├── App.svelte
│ ├── lib/
│ │ ├── api.ts (server API client)
│ │ ├── mpv.ts (mpv IPC bridge via Tauri commands)
│ │ ├── ws.ts (WebSocket export progress)
│ │ └── stores.ts (Svelte stores: files, markers, settings)
│ ├── components/
│ │ ├── FileBrowser.svelte
│ │ ├── Timeline.svelte
│ │ ├── CropOverlay.svelte
│ │ ├── ExportPanel.svelte
│ │ ├── SettingsPanel.svelte
│ │ └── ProfileBar.svelte
│ └── main.ts
├── package.json
└── vite.config.ts
```
## Implementation order
1. Scaffold Tauri + Svelte project
2. mpv sidecar: spawn, IPC, basic play/pause/seek
3. API client module + server connection
4. File browser component
5. Video playback: load file → stream URL → mpv
6. Canvas timeline: cursor, seek, markers
7. Export panel + WebSocket progress
8. Crop overlay + keyframes
9. Lock mode, autoclip, play region
10. Profiles, subprofiles, hidden files
11. Keyboard shortcuts
12. Settings persistence
13. Package for Linux (.deb / .AppImage)
14. Package for Mac (.dmg)
File diff suppressed because it is too large Load Diff
+207
View File
@@ -0,0 +1,207 @@
# 8-cut Server API Design
## Goal
Run 8-cut as a FastAPI server on Unraid (Docker) so a Tauri desktop client on Mac can edit remotely over WireGuard — no file transfers, no auth.
## Architecture
```
Unraid (Docker container):
FastAPI + ffmpeg + SQLite
├── /api/files list videos from mounted volumes
├── /api/stream/{path} transcoded video (cached, no audio)
├── /api/audio/{path} full-quality audio (cached, passthrough)
├── /api/video/{path} raw file (for reference/download)
├── /api/markers CRUD markers per profile
├── /api/profiles list/create profiles
├── /api/export trigger + manage exports
├── /api/labels label history
├── /api/hidden hidden file management
└── ws://…/ws/export real-time export progress
Mac (Tauri + Svelte + libmpv):
├── mpv plays stream URL (video) + audio URL separately
├── Canvas timeline + crop overlay + keyframes
├── Full UI: profiles, subprofiles, settings
└── Stateless — all state lives on server
```
## Docker mounts
| Mount | Purpose | Env var |
|-------------|--------------------------------|--------------|
| `/videos` | Source video files (read-only) | `MEDIA_DIRS` |
| `/exports` | Export output | `EXPORT_DIR` |
| `/data` | SQLite DB + transcode cache | `DB_PATH`, `CACHE_DIR` |
`MEDIA_DIRS` supports multiple paths: `/videos1,/videos2`.
## Video streaming with transcode cache
The client needs low-bitrate video for scrubbing over the network but full-quality audio for accurate editing.
**Flow:**
1. Client requests `/api/stream/{path}?quality=low`
2. Server checks cache: `{CACHE_DIR}/{quality}/{hash}.mp4`
3. If cached → serve with range requests (instant seeking)
4. If not → start background ffmpeg transcode, return `202 Accepted` with job ID
5. Client polls or gets WebSocket notification when ready
6. Audio: `/api/audio/{path}` extracts audio (passthrough, fast) to cache on first request
**Quality presets:**
| Preset | Resolution | Bitrate |
|----------|-----------|----------|
| `potato` | 480p | ~500 Kbps |
| `low` | 720p | ~2 Mbps |
| `medium` | 1080p | ~5 Mbps |
| `high` | original | ~10 Mbps |
Each quality level cached separately. Client can switch quality — mpv reloads the URL.
**mpv on client:**
```
video = http://server/api/stream/file.mp4?quality=low
audio = http://server/api/audio/file.mp4
```
mpv's `--audio-file=` flag plays both in sync with frame-accurate seeking.
## API endpoints
### Files
```
GET /api/files?root={root}
→ [{path, name, size, duration?, markers_count}]
GET /api/video/{path}
→ raw file with range requests
GET /api/stream/{path}?quality=low|medium|high|potato
→ cached transcoded video (no audio), range requests
→ 202 if transcode in progress
GET /api/audio/{path}
→ cached full-quality audio, range requests
→ 202 if extraction in progress
GET /api/cache/status/{path}
→ {qualities: {potato: "ready", low: "transcoding", ...}, audio: "ready"}
```
### Markers & profiles
```
GET /api/markers/{filename}?profile=default
→ [{start_time, marker_number, output_path}]
GET /api/profiles
→ ["default", "intense", ...]
GET /api/labels
→ ["dog barking", "rain", ...]
```
### Export
```
POST /api/export
body: {input_path, cursor, folder_suffix?, name, clips, spread,
short_side?, portrait_ratio?, crop_center, format,
label?, category?, profile, crop_keyframes?,
rand_portrait?, rand_square?, track_subject?}
→ {job_id}
GET /api/export/{job_id}
→ {status, completed, total, outputs: [...]}
DELETE /api/export/{output_path}
→ delete from DB + disk
WS /ws/export
→ server pushes: {type: "clip_done", path: "..."} | {type: "all_done"} | {type: "error", msg: "..."}
```
### Hidden files
```
POST /api/hidden/{filename}?profile=default
DELETE /api/hidden/{filename}?profile=default
GET /api/hidden?profile=default
→ ["file1.mp4", "file2.mp4"]
```
## Code reuse from main.py
**Extracted to shared module (used by both server and Qt app):**
- `ProcessedDB` — SQLite operations
- `build_ffmpeg_command` — ffmpeg command construction
- `build_audio_extract_command`
- `build_export_path` / `build_sequence_dir`
- `detect_hw_encoders`
- `upsert_clip_annotation` / `remove_clip_annotation`
- `apply_keyframes_to_jobs` / `resolve_keyframe`
- `track_centers_for_jobs` (subject tracking)
**Server-specific (new):**
- FastAPI app + route handlers
- Transcode cache manager
- Export worker (plain threading, replaces QThread-based ExportWorker)
- File listing / media root scanning
- WebSocket export progress broadcaster
**Tauri client (new, Svelte):**
- mpv integration via Tauri plugin or sidecar
- Canvas-based timeline widget
- Canvas-based crop overlay
- All UI controls
- API client module
## Dockerfile
```dockerfile
FROM python:3.12-slim
RUN apt-get update && apt-get install -y ffmpeg && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY server/ .
RUN pip install --no-cache-dir fastapi uvicorn
EXPOSE 8000
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
```
## Project structure
```
8-cut/
├── main.py (existing Qt app, unchanged)
├── core/ (shared logic, extracted from main.py)
│ ├── __init__.py
│ ├── db.py (ProcessedDB)
│ ├── ffmpeg.py (build commands, detect encoders)
│ ├── export.py (ExportWorker — plain threading)
│ ├── paths.py (build_export_path, build_sequence_dir)
│ └── annotations.py (dataset.json helpers)
├── server/
│ ├── app.py (FastAPI app)
│ ├── routes/
│ │ ├── files.py
│ │ ├── stream.py
│ │ ├── markers.py
│ │ ├── export.py
│ │ └── hidden.py
│ ├── cache.py (transcode cache manager)
│ ├── ws.py (WebSocket handler)
│ └── config.py (env vars, settings)
├── client/ (Tauri + Svelte — future)
│ └── ...
├── Dockerfile
└── docker-compose.yml
```
## Implementation order
1. Extract shared logic from main.py → `core/`
2. Update main.py to import from `core/` (verify Qt app still works)
3. Build FastAPI server with file listing + video serving
4. Add transcode cache + audio extraction
5. Add markers/profiles/labels/hidden API
6. Add export endpoint + WebSocket progress
7. Dockerfile + docker-compose
8. (Later) Tauri client
@@ -0,0 +1,948 @@
# Server API Implementation Plan
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
**Goal:** Extract shared logic from main.py into a `core/` package, then build the FastAPI server that serves video files, manages the DB, and runs exports.
**Architecture:** Shared logic (DB, ffmpeg, paths, annotations, tracking) moves to `core/`. Both `main.py` (Qt app) and `server/` import from `core/`. The server adds HTTP video streaming with transcode cache, REST endpoints, and WebSocket export progress.
**Tech Stack:** Python 3.12, FastAPI, uvicorn, SQLite, ffmpeg
---
### Task 1: Create core/ package — paths and helpers
**Files:**
- Create: `core/__init__.py`
- Create: `core/paths.py`
**Step 1: Create core/__init__.py**
```python
# empty — package marker
```
**Step 2: Create core/paths.py**
Extract from main.py lines 36-74: `_frozen_path`, `_bin`, `_log`, `build_export_path`, `build_sequence_dir`, `format_time`.
```python
import os
import sys
from datetime import datetime
from pathlib import Path
def _frozen_path() -> Path:
if getattr(sys, "frozen", False):
return Path(sys._MEIPASS)
return Path(__file__).resolve().parent.parent
def _bin(name: str) -> str:
p = _frozen_path() / name
if p.exists():
return str(p)
return name
def _log(*args) -> None:
ts = datetime.now().strftime("%H:%M:%S")
print(f"[8-cut {ts}]", *args, file=sys.stderr)
def build_export_path(folder: str, basename: str, counter: int, sub: int | None = None) -> str:
group = f"{basename}_{counter:03d}"
name = f"{group}_{sub}" if sub is not None else group
return os.path.join(folder, group, name + ".mp4")
def build_sequence_dir(folder: str, basename: str, counter: int, sub: int | None = None) -> str:
group = f"{basename}_{counter:03d}"
name = f"{group}_{sub}" if sub is not None else group
return os.path.join(folder, group, name)
def format_time(seconds: float) -> str:
m = int(seconds // 60)
s = int(seconds % 60 * 10) / 10
return f"{m}:{s:04.1f}"
```
**Step 3: Commit**
```bash
git add core/
git commit -m "feat: create core/paths module with shared path helpers"
```
---
### Task 2: Create core/ffmpeg.py
**Files:**
- Create: `core/ffmpeg.py`
**Step 1: Create core/ffmpeg.py**
Extract from main.py lines 77-112 and 244-289: `_RATIOS`, `_portrait_crop_filter`, `resolve_keyframe`, `apply_keyframes_to_jobs`, `build_ffmpeg_command`, `build_audio_extract_command`, `detect_hw_encoders`. (Lines 115-188 are also ffmpeg-related. Lines 191-241 are annotations — extracted separately in Task 4.)
```python
import os
import re
import subprocess
from .paths import _bin, _log
_RATIOS: dict[str, tuple[int, int]] = {
"9:16": (9, 16),
"4:5": (4, 5),
"1:1": (1, 1),
}
def _portrait_crop_filter(ratio: str, crop_center: float) -> str:
num, den = _RATIOS[ratio]
cw = f"ih*{num}/{den}"
x = f"max(0\\,min((iw-{cw})*{crop_center}\\,iw-{cw}))"
return f"crop={cw}:ih:{x}:0"
def resolve_keyframe(
keyframes: list[tuple[float, float, str | None, bool, bool]],
t: float,
tolerance: float = 0.05,
) -> tuple[float, float, str | None, bool, bool] | None:
result = None
for kf in keyframes:
if kf[0] <= t + tolerance:
result = kf
else:
break
return result
def apply_keyframes_to_jobs(
jobs: list[tuple[float, str, str | None, float]],
keyframes: list[tuple[float, float, str | None, bool, bool]],
base_center: float,
base_ratio: str | None,
base_rand_p: bool,
base_rand_s: bool,
) -> list[tuple[float, str, str | None, float, bool, bool]]:
result = []
for s, o, _r, _c in jobs:
kf = resolve_keyframe(keyframes, s)
if kf is not None:
_, center, ratio, rp, rs = kf
else:
center, ratio, rp, rs = base_center, base_ratio, base_rand_p, base_rand_s
result.append((s, o, ratio, center, rp, rs))
return result
def build_ffmpeg_command(
input_path: str, start: float, output_path: str,
short_side: int | None = None,
portrait_ratio: str | None = None,
crop_center: float = 0.5,
image_sequence: bool = False,
encoder: str = "libx264",
) -> list[str]:
use_hw_vaapi = encoder == "h264_vaapi" and not image_sequence
cmd = [_bin("ffmpeg"), "-y"]
if use_hw_vaapi:
cmd += ["-hwaccel", "vaapi", "-hwaccel_output_format", "vaapi",
"-vaapi_device", "/dev/dri/renderD128"]
cmd += ["-threads", "0", "-ss", str(start), "-i", input_path, "-t", "8"]
filters: list[str] = []
if portrait_ratio is not None:
filters.append(_portrait_crop_filter(portrait_ratio, crop_center))
if short_side is not None:
filters.append(
f"scale='if(lt(iw,ih),{short_side},-2)':'if(lt(iw,ih),-2,{short_side})':flags=lanczos"
)
if use_hw_vaapi:
if filters:
filters.insert(0, "hwdownload")
filters.insert(1, "format=nv12")
filters.append("format=nv12")
filters.append("hwupload")
if filters:
cmd += ["-vf", ",".join(filters)]
if image_sequence:
cmd += ["-an", "-c:v", "libwebp", "-quality", "92", "-compression_level", "1",
os.path.join(output_path, "frame_%04d.webp")]
else:
cmd += ["-c:v", encoder, "-c:a", "pcm_s16le", output_path]
return cmd
def build_audio_extract_command(input_path: str, start: float, sequence_dir: str) -> list[str]:
audio_path = sequence_dir + ".wav"
return [_bin("ffmpeg"), "-y", "-ss", str(start), "-i", input_path,
"-t", "8", "-vn", "-c:a", "pcm_s16le", audio_path]
def detect_hw_encoders() -> list[str]:
_HW_ENCODERS = ["h264_nvenc", "h264_vaapi", "h264_qsv", "h264_amf", "h264_videotoolbox"]
try:
result = subprocess.run(
[_bin("ffmpeg"), "-hide_banner", "-encoders"],
capture_output=True, text=True, timeout=5,
)
if result.returncode != 0:
return []
output = result.stdout
except Exception:
return []
available = []
for enc in _HW_ENCODERS:
if re.search(rf'\b{enc}\b', output):
available.append(enc)
if available:
_log(f"HW encoders detected: {', '.join(available)}")
else:
_log("No HW encoders detected — GPU export unavailable")
return available
```
**Step 2: Commit**
```bash
git add core/ffmpeg.py
git commit -m "feat: create core/ffmpeg module with ffmpeg helpers"
```
---
### Task 3: Create core/db.py
**Files:**
- Create: `core/db.py`
**Step 1: Create core/db.py**
Extract the entire `ProcessedDB` class from main.py lines 398-626. Import `_log` from `core.paths`.
```python
import sqlite3
from datetime import datetime, timezone
from pathlib import Path
from .paths import _log
class ProcessedDB:
_SCHEMA_VERSION = 3
def __init__(self, db_path: str | None = None):
# ... exact copy of existing class ...
```
Copy the full class body verbatim — all methods unchanged.
**Step 2: Commit**
```bash
git add core/db.py
git commit -m "feat: create core/db module with ProcessedDB"
```
---
### Task 4: Create core/annotations.py
**Files:**
- Create: `core/annotations.py`
**Step 1: Create core/annotations.py**
Extract from main.py lines 191-241: `build_annotation_json_path`, `remove_clip_annotation`, `upsert_clip_annotation`.
```python
import json
import os
def build_annotation_json_path(folder: str) -> str:
return os.path.join(folder, "dataset.json")
def remove_clip_annotation(folder: str, clip_path: str) -> None:
json_path = build_annotation_json_path(folder)
if not os.path.exists(json_path):
return
abs_path = os.path.abspath(clip_path)
with open(json_path, "r", encoding="utf-8") as f:
try:
entries = json.load(f)
except (json.JSONDecodeError, ValueError):
return
entries = [e for e in entries if e.get("path") != abs_path]
with open(json_path, "w", encoding="utf-8") as f:
json.dump(entries, f, indent=2, ensure_ascii=False)
f.write("\n")
def upsert_clip_annotation(folder: str, clip_path: str, label: str) -> None:
if not label.strip():
return
os.makedirs(folder, exist_ok=True)
json_path = build_annotation_json_path(folder)
entries: list[dict] = []
if os.path.exists(json_path):
with open(json_path, "r", encoding="utf-8") as f:
try:
entries = json.load(f)
except (json.JSONDecodeError, ValueError):
entries = []
abs_path = os.path.abspath(clip_path)
entry: dict = {"path": abs_path, "label": label}
for i, e in enumerate(entries):
if e.get("path") == abs_path:
entries[i] = entry
break
else:
entries.append(entry)
with open(json_path, "w", encoding="utf-8") as f:
json.dump(entries, f, indent=2, ensure_ascii=False)
f.write("\n")
```
**Step 2: Commit**
```bash
git add core/annotations.py
git commit -m "feat: create core/annotations module"
```
---
### Task 5: Create core/export.py
**Files:**
- Create: `core/export.py`
**Step 1: Create core/export.py**
A plain-threading version of `ExportWorker` (no QThread dependency). Used by the server. The Qt app continues using its own QThread-based worker.
```python
import os
import subprocess
import threading
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import Callable
from .ffmpeg import build_ffmpeg_command, build_audio_extract_command
from .paths import _bin, _log
class ExportRunner:
"""Run ffmpeg export jobs in a background thread pool.
Callbacks:
on_clip_done(path: str)
on_all_done()
on_error(msg: str)
"""
def __init__(
self,
input_path: str,
jobs: list[tuple[float, str, str | None, float]],
short_side: int | None = None,
image_sequence: bool = False,
max_workers: int | None = None,
encoder: str = "libx264",
on_clip_done: Callable[[str], None] | None = None,
on_all_done: Callable[[], None] | None = None,
on_error: Callable[[str], None] | None = None,
):
self._input = input_path
self._jobs = jobs
self._short_side = short_side
self._image_sequence = image_sequence
self._max_workers = max_workers
self._encoder = encoder
self._on_clip_done = on_clip_done
self._on_all_done = on_all_done
self._on_error = on_error
self._cancel = False
self._procs: list[subprocess.Popen] = []
self._procs_lock = threading.Lock()
self._thread: threading.Thread | None = None
def start(self):
self._thread = threading.Thread(target=self._run, daemon=True)
self._thread.start()
def cancel(self):
self._cancel = True
with self._procs_lock:
for proc in self._procs:
try:
proc.kill()
except OSError:
pass
def is_running(self) -> bool:
return self._thread is not None and self._thread.is_alive()
def _run_one(self, start: float, output: str,
portrait_ratio: str | None, crop_center: float) -> str:
if self._cancel:
raise RuntimeError("cancelled")
if self._image_sequence:
os.makedirs(output, exist_ok=True)
cmd = build_ffmpeg_command(
self._input, start, output,
short_side=self._short_side,
portrait_ratio=portrait_ratio,
crop_center=crop_center,
image_sequence=self._image_sequence,
encoder=self._encoder,
)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
with self._procs_lock:
self._procs.append(proc)
try:
_, stderr = proc.communicate(timeout=120)
except subprocess.TimeoutExpired:
proc.kill()
raise RuntimeError("ffmpeg timed out")
finally:
with self._procs_lock:
self._procs.remove(proc)
if self._cancel:
raise RuntimeError("cancelled")
if proc.returncode != 0:
msg = stderr.decode(errors='replace')[-500:] if stderr else "ffmpeg failed"
raise RuntimeError(msg)
if self._image_sequence:
audio_cmd = build_audio_extract_command(self._input, start, output)
subprocess.run(audio_cmd, capture_output=True, text=True, timeout=60)
return output
def _run(self):
cap = self._max_workers or (os.cpu_count() or 2)
workers = min(len(self._jobs), cap)
try:
with ThreadPoolExecutor(max_workers=workers) as pool:
futures = {
pool.submit(self._run_one, s, o, pr, cc): o
for s, o, pr, cc in self._jobs
}
for fut in as_completed(futures):
if self._cancel:
break
try:
path = fut.result()
if self._on_clip_done:
self._on_clip_done(path)
except Exception as e:
if "cancelled" not in str(e) and self._on_error:
self._on_error(str(e))
except Exception as e:
if self._on_error:
self._on_error(str(e))
return
if self._cancel:
return
if self._on_all_done:
self._on_all_done()
```
**Step 2: Commit**
```bash
git add core/export.py
git commit -m "feat: create core/export module with ExportRunner"
```
---
### Task 6: Create core/tracking.py
**Files:**
- Create: `core/tracking.py`
**Step 1: Create core/tracking.py**
Extract from main.py lines 294-395: YOLO tracking functions.
```python
import os
import subprocess
import tempfile
from .paths import _bin, _log
_yolo_model = None
def _get_yolo():
global _yolo_model
if _yolo_model is None:
try:
from ultralytics import YOLO
_yolo_model = YOLO("yolov8n.pt")
_log("YOLO model loaded")
except ImportError:
_log("ultralytics not installed — tracking disabled")
return None
except Exception as e:
_log(f"YOLO load failed: {e}")
return None
return _yolo_model
def extract_frame_cv(video_path: str, time: float):
try:
import cv2
import numpy as np
except ImportError:
return None
fd, tmp = tempfile.mkstemp(suffix=".png")
os.close(fd)
try:
cmd = [_bin("ffmpeg"), "-y", "-ss", str(time), "-i", video_path,
"-frames:v", "1", tmp]
result = subprocess.run(cmd, capture_output=True, timeout=10)
if result.returncode != 0:
return None
return cv2.imread(tmp)
except Exception:
return None
finally:
if os.path.exists(tmp):
os.unlink(tmp)
def detect_subject_center(
video_path: str, time: float, target_cls: int | None, last_x: float, last_y: float,
) -> tuple[int | None, float, float] | None:
model = _get_yolo()
if model is None:
return None
frame = extract_frame_cv(video_path, time)
if frame is None:
return None
results = model(frame, verbose=False)
if not results or len(results[0].boxes) == 0:
return None
h, w = frame.shape[:2]
dets = []
for box in results[0].boxes:
x1, y1, x2, y2 = box.xyxy[0].tolist()
cls = int(box.cls[0])
cx = (x1 + x2) / 2 / w
cy = (y1 + y2) / 2 / h
dets.append((cls, cx, cy))
def score(d):
cls_penalty = 0 if (target_cls is None or d[0] == target_cls) else 1.0
dist = (d[1] - last_x) ** 2 + (d[2] - last_y) ** 2
return cls_penalty + dist
best = min(dets, key=score)
return best
def track_centers_for_jobs(
video_path: str, cursor: float, crop_center: float,
starts: list[float],
) -> list[float]:
ref = detect_subject_center(video_path, cursor, None, crop_center, 0.5)
if ref is None:
_log("Tracking: no detection at cursor, using fixed center")
return [crop_center] * len(starts)
target_cls, last_x, last_y = ref
_log(f"Tracking: target class={target_cls} at ({last_x:.2f}, {last_y:.2f})")
centers = []
for t in starts:
det = detect_subject_center(video_path, t, target_cls, last_x, last_y)
if det is not None:
_, cx, cy = det
_log(f" t={t:.2f}s → center={cx:.3f}")
centers.append(cx)
last_x, last_y = cx, cy
else:
_log(f" t={t:.2f}s → lost, reusing {last_x:.3f}")
centers.append(last_x)
return centers
```
**Step 2: Commit**
```bash
git add core/tracking.py
git commit -m "feat: create core/tracking module with YOLO subject tracking"
```
---
### Task 7: Update main.py to import from core/
**Files:**
- Modify: `main.py`
**Step 1: Replace function definitions with imports**
At the top of main.py, after the existing stdlib imports (line 17), add:
```python
from core.paths import _bin, _log, build_export_path, build_sequence_dir, format_time
from core.ffmpeg import (
_RATIOS, resolve_keyframe, apply_keyframes_to_jobs,
build_ffmpeg_command, build_audio_extract_command, detect_hw_encoders,
)
from core.db import ProcessedDB
from core.annotations import remove_clip_annotation, upsert_clip_annotation
from core.tracking import track_centers_for_jobs
```
**Step 2: Delete the extracted function definitions and dead imports**
Remove definitions from main.py:
- Lines 36-74: `_frozen_path`, `_bin`, `_log`, `build_export_path`, `build_sequence_dir`, `format_time`
- Lines 77-188: `resolve_keyframe`, `apply_keyframes_to_jobs`, `build_ffmpeg_command`, `build_audio_extract_command`
- Lines 191-241: annotation functions (`build_annotation_json_path`, `remove_clip_annotation`, `upsert_clip_annotation`)
- Lines 244-289: `detect_hw_encoders`, `_RATIOS`, `_portrait_crop_filter`
- Lines 294-395: tracking functions (`_yolo_model`, `_get_yolo`, `extract_frame_cv`, `detect_subject_center`, `track_centers_for_jobs`)
- Lines 398-626: `ProcessedDB` class
Remove now-dead stdlib imports from the top of main.py:
- `re` (only used in `detect_hw_encoders`)
- `json` (only used in annotation functions)
- `sqlite3` (only used in `ProcessedDB`)
- `tempfile` (only used in `extract_frame_cv`)
- `datetime`, `timezone` from the datetime import (only used in `_log` and `ProcessedDB`)
Keep in main.py:
- `_SELVA_CATEGORIES` (UI constant, line 291)
- `_RATIOS` reference — imported from core.ffmpeg
- `ExportWorker` (QThread-based, stays in main.py — the server uses `core.export.ExportRunner` instead)
- `_DBWorker` and `FrameGrabber` (QThread-based, stay in main.py)
**Step 3: Verify Qt app still works**
```bash
python main.py
```
Open a video, export a clip, check markers — verify nothing broke.
**Step 4: Commit**
```bash
git add main.py
git commit -m "refactor: import shared logic from core/ instead of inline definitions"
```
---
### Task 8: Create server/config.py
**Files:**
- Create: `server/__init__.py` (empty package marker)
- Create: `server/config.py`
**Step 1: Create `server/__init__.py`**
```python
# empty — package marker
```
**Step 2: Create config**
```python
import os
from pathlib import Path
MEDIA_DIRS: list[str] = [
d.strip() for d in os.environ.get("MEDIA_DIRS", str(Path.home())).split(",") if d.strip()
]
EXPORT_DIR: str = os.environ.get("EXPORT_DIR", str(Path.home() / "8cut-exports"))
DB_PATH: str = os.environ.get("DB_PATH", str(Path.home() / ".8cut.db"))
CACHE_DIR: str = os.environ.get("CACHE_DIR", str(Path.home() / ".8cut-cache"))
HOST: str = os.environ.get("HOST", "0.0.0.0")
PORT: int = int(os.environ.get("PORT", "8000"))
VIDEO_EXTENSIONS = {".mp4", ".mkv", ".avi", ".mov", ".webm", ".ts", ".flv", ".wmv"}
QUALITY_PRESETS = {
"potato": {"height": 480, "bitrate": "500k"},
"low": {"height": 720, "bitrate": "2M"},
"medium": {"height": 1080, "bitrate": "5M"},
"high": {"height": 0, "bitrate": "10M"}, # 0 = original resolution
}
```
**Step 2: Commit**
```bash
git add server/
git commit -m "feat: create server/config with env var settings and quality presets"
```
---
### Task 9: Create server/app.py — FastAPI skeleton + file listing
**Files:**
- Create: `server/app.py`
- Create: `server/routes/__init__.py`
- Create: `server/routes/files.py`
**Step 1: Create FastAPI app**
`server/app.py`:
```python
from fastapi import FastAPI
from .routes import files, stream, markers, export, hidden
app = FastAPI(title="8-cut Server")
app.include_router(files.router, prefix="/api")
app.include_router(stream.router, prefix="/api")
app.include_router(markers.router, prefix="/api")
app.include_router(export.router, prefix="/api")
app.include_router(hidden.router, prefix="/api")
```
**Step 2: Create file listing route**
`server/routes/files.py`:
```python
import os
from fastapi import APIRouter, Query
from ..config import MEDIA_DIRS, VIDEO_EXTENSIONS
router = APIRouter()
def _scan_videos(root: str) -> list[dict]:
results = []
for dirpath, _, filenames in os.walk(root):
for f in sorted(filenames):
if os.path.splitext(f)[1].lower() in VIDEO_EXTENSIONS:
full = os.path.join(dirpath, f)
rel = os.path.relpath(full, root)
results.append({
"name": f,
"path": rel,
"root": root,
"size": os.path.getsize(full),
})
return results
@router.get("/files")
def list_files(root: str | None = Query(None)):
dirs = [root] if root and root in MEDIA_DIRS else MEDIA_DIRS
files = []
for d in dirs:
files.extend(_scan_videos(d))
return files
@router.get("/roots")
def list_roots():
return MEDIA_DIRS
```
**Step 3: Create `server/routes/__init__.py`**
```python
# empty — package marker
```
**Step 4: Create stub routers** so app.py imports don't fail. Each file gets a minimal router — later tasks fill in the real endpoints.
`server/routes/stream.py`:
```python
from fastapi import APIRouter
router = APIRouter()
```
`server/routes/markers.py`:
```python
from fastapi import APIRouter
router = APIRouter()
```
`server/routes/export.py`:
```python
from fastapi import APIRouter
router = APIRouter()
```
`server/routes/hidden.py`:
```python
from fastapi import APIRouter
router = APIRouter()
```
**Step 5: Commit**
```bash
git add server/
git commit -m "feat: add FastAPI app with file listing endpoint"
```
---
### Task 10: Create server/routes/stream.py — video serving + transcode cache
**Files:**
- Create: `server/cache.py`
- Create: `server/routes/stream.py`
**Step 1: Create cache manager**
`server/cache.py` handles:
- Computing cache paths from source file hash + quality
- Checking cache status
- Launching background ffmpeg transcodes
- Tracking in-progress jobs
**Step 2: Create stream routes**
```
GET /api/video/{path} — raw file, range requests
GET /api/stream/{path}?quality=low — cached transcode, range requests (202 if not ready)
GET /api/audio/{path} — cached audio extraction, range requests (202 if not ready)
GET /api/cache/status/{path} — cache status for all qualities
```
**Step 3: Commit**
```bash
git add server/cache.py server/routes/stream.py
git commit -m "feat: add video streaming with transcode cache and audio extraction"
```
---
### Task 11: Create server/routes/markers.py — DB endpoints
**Files:**
- Create: `server/routes/markers.py`
**Step 1: Create markers/profiles/labels routes**
```
GET /api/markers/{filename}?profile=default
GET /api/profiles
GET /api/labels
```
Uses `ProcessedDB` singleton from `core.db`.
**Step 2: Commit**
```bash
git add server/routes/markers.py
git commit -m "feat: add markers, profiles, and labels API endpoints"
```
---
### Task 12: Create server/routes/export.py + WebSocket
**Files:**
- Create: `server/routes/export.py`
- Create: `server/ws.py`
**Step 1: Create export routes + WS**
```
POST /api/export — start export job
GET /api/export/{id} — check job status
DELETE /api/export/{path} — delete export from DB + disk
WS /ws/export — real-time progress
```
Uses `ExportRunner` from `core.export`.
**Step 2: Commit**
```bash
git add server/routes/export.py server/ws.py
git commit -m "feat: add export endpoint with WebSocket progress"
```
---
### Task 13: Create server/routes/hidden.py
**Files:**
- Create: `server/routes/hidden.py`
**Step 1: Create hidden file routes**
```
POST /api/hidden/{filename}?profile=default
DELETE /api/hidden/{filename}?profile=default
GET /api/hidden?profile=default
```
**Step 2: Commit**
```bash
git add server/routes/hidden.py
git commit -m "feat: add hidden files API endpoints"
```
---
### Task 14: Create Dockerfile + docker-compose.yml
**Files:**
- Create: `Dockerfile`
- Create: `docker-compose.yml`
**Step 1: Create Dockerfile**
```dockerfile
FROM python:3.12-slim
RUN apt-get update && apt-get install -y ffmpeg && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY core/ core/
COPY server/ server/
# Note: ultralytics + opencv-python needed only if subject tracking is used.
# Add them here if tracking is required on the server.
RUN pip install --no-cache-dir fastapi uvicorn
EXPOSE 8000
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "8000"]
```
**Step 2: Create docker-compose.yml**
```yaml
services:
8cut:
build: .
ports:
- "8000:8000"
volumes:
- /path/to/videos:/videos:ro
- /path/to/exports:/exports
- 8cut-data:/data
environment:
MEDIA_DIRS: /videos
EXPORT_DIR: /exports
DB_PATH: /data/8cut.db
CACHE_DIR: /data/cache
volumes:
8cut-data:
```
**Step 3: Commit**
```bash
git add Dockerfile docker-compose.yml
git commit -m "feat: add Dockerfile and docker-compose for server deployment"
```
+1774 -781
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -1,3 +1,4 @@
PyQt6>=6.4
python-mpv>=1.0
pytest>=7.0
ultralytics>=8.0
View File
+29
View File
@@ -0,0 +1,29 @@
from fastapi import FastAPI, WebSocket
from fastapi.middleware.cors import CORSMiddleware
from core.db import ProcessedDB
from .config import DB_PATH
from .routes import files, stream, markers, export, hidden
from . import ws
app = FastAPI(title="8-cut Server")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
db = ProcessedDB(DB_PATH)
app.include_router(files.router, prefix="/api")
app.include_router(stream.router, prefix="/api")
app.include_router(markers.router, prefix="/api")
app.include_router(export.router, prefix="/api")
app.include_router(hidden.router, prefix="/api")
@app.websocket("/ws/export")
async def export_ws(websocket: WebSocket):
await ws.connect(websocket)
+171
View File
@@ -0,0 +1,171 @@
import hashlib
import os
import subprocess
import threading
from enum import Enum
from core.paths import _bin, _log
from .config import CACHE_DIR, QUALITY_PRESETS
class CacheStatus(str, Enum):
READY = "ready"
TRANSCODING = "transcoding"
MISSING = "missing"
ERROR = "error"
_jobs_lock = threading.Lock()
_active_jobs: dict[str, threading.Thread] = {}
def _cache_key(source_path: str) -> str:
"""Stable hash from absolute source path."""
return hashlib.sha256(source_path.encode()).hexdigest()[:16]
def cache_path(source_path: str, quality: str) -> str:
key = _cache_key(source_path)
return os.path.join(CACHE_DIR, quality, f"{key}.mp4")
def audio_cache_path(source_path: str) -> str:
key = _cache_key(source_path)
return os.path.join(CACHE_DIR, "audio", f"{key}.wav")
def get_status(source_path: str, quality: str) -> CacheStatus:
cp = cache_path(source_path, quality)
if os.path.isfile(cp):
return CacheStatus.READY
job_key = f"{source_path}:{quality}"
with _jobs_lock:
if job_key in _active_jobs and _active_jobs[job_key].is_alive():
return CacheStatus.TRANSCODING
return CacheStatus.MISSING
def get_audio_status(source_path: str) -> CacheStatus:
ap = audio_cache_path(source_path)
if os.path.isfile(ap):
return CacheStatus.READY
job_key = f"{source_path}:audio"
with _jobs_lock:
if job_key in _active_jobs and _active_jobs[job_key].is_alive():
return CacheStatus.TRANSCODING
return CacheStatus.MISSING
def get_all_statuses(source_path: str) -> dict:
result = {}
for q in QUALITY_PRESETS:
result[q] = get_status(source_path, q)
result["audio"] = get_audio_status(source_path)
return result
def _transcode_worker(source_path: str, quality: str) -> None:
preset = QUALITY_PRESETS[quality]
out = cache_path(source_path, quality)
os.makedirs(os.path.dirname(out), exist_ok=True)
tmp = out + ".tmp.mp4"
cmd = [_bin("ffmpeg"), "-y", "-i", source_path, "-an"]
if preset["height"] > 0:
cmd += [
"-vf", f"scale=-2:{preset['height']}:flags=lanczos",
]
cmd += [
"-c:v", "libx264",
"-preset", "fast",
"-b:v", preset["bitrate"],
"-movflags", "+faststart",
tmp,
]
_log(f"Transcode start: {source_path} @ {quality}")
try:
result = subprocess.run(cmd, capture_output=True, text=True, timeout=3600)
if result.returncode == 0:
os.rename(tmp, out)
_log(f"Transcode done: {out}")
else:
_log(f"Transcode failed: {result.stderr[-300:]}")
if os.path.exists(tmp):
os.unlink(tmp)
except Exception as e:
_log(f"Transcode error: {e}")
if os.path.exists(tmp):
os.unlink(tmp)
def _audio_extract_worker(source_path: str) -> None:
out = audio_cache_path(source_path)
os.makedirs(os.path.dirname(out), exist_ok=True)
tmp = out + ".tmp.wav"
cmd = [
_bin("ffmpeg"), "-y",
"-i", source_path,
"-vn",
"-c:a", "pcm_s16le",
tmp,
]
_log(f"Audio extract start: {source_path}")
try:
result = subprocess.run(cmd, capture_output=True, text=True, timeout=600)
if result.returncode == 0:
os.rename(tmp, out)
_log(f"Audio extract done: {out}")
else:
_log(f"Audio extract failed: {result.stderr[-300:]}")
if os.path.exists(tmp):
os.unlink(tmp)
except Exception as e:
_log(f"Audio extract error: {e}")
if os.path.exists(tmp):
os.unlink(tmp)
def _prune_dead_jobs() -> None:
"""Remove finished threads from _active_jobs. Must be called under _jobs_lock."""
dead = [k for k, t in _active_jobs.items() if not t.is_alive()]
for k in dead:
del _active_jobs[k]
def ensure_transcode(source_path: str, quality: str) -> CacheStatus:
"""Start transcode if not cached. Returns current status."""
status = get_status(source_path, quality)
if status != CacheStatus.MISSING:
return status
job_key = f"{source_path}:{quality}"
with _jobs_lock:
_prune_dead_jobs()
if job_key in _active_jobs and _active_jobs[job_key].is_alive():
return CacheStatus.TRANSCODING
t = threading.Thread(target=_transcode_worker, args=(source_path, quality), daemon=True)
_active_jobs[job_key] = t
t.start()
return CacheStatus.TRANSCODING
def ensure_audio(source_path: str) -> CacheStatus:
"""Start audio extraction if not cached. Returns current status."""
status = get_audio_status(source_path)
if status != CacheStatus.MISSING:
return status
job_key = f"{source_path}:audio"
with _jobs_lock:
_prune_dead_jobs()
if job_key in _active_jobs and _active_jobs[job_key].is_alive():
return CacheStatus.TRANSCODING
t = threading.Thread(target=_audio_extract_worker, args=(source_path,), daemon=True)
_active_jobs[job_key] = t
t.start()
return CacheStatus.TRANSCODING
+21
View File
@@ -0,0 +1,21 @@
import os
from pathlib import Path
MEDIA_DIRS: list[str] = [
d.strip() for d in os.environ.get("MEDIA_DIRS", str(Path.home())).split(",") if d.strip()
]
EXPORT_DIR: str = os.environ.get("EXPORT_DIR", str(Path.home() / "8cut-exports"))
DB_PATH: str = os.environ.get("DB_PATH", str(Path.home() / ".8cut.db"))
CACHE_DIR: str = os.environ.get("CACHE_DIR", str(Path.home() / ".8cut-cache"))
HOST: str = os.environ.get("HOST", "0.0.0.0")
PORT: int = int(os.environ.get("PORT", "8000"))
VIDEO_EXTENSIONS = {".mp4", ".mkv", ".avi", ".mov", ".webm", ".ts", ".flv", ".wmv"}
QUALITY_PRESETS = {
"potato": {"height": 480, "bitrate": "500k"},
"low": {"height": 720, "bitrate": "2M"},
"medium": {"height": 1080, "bitrate": "5M"},
"high": {"height": 0, "bitrate": "10M"}, # 0 = original resolution
}
View File
+227
View File
@@ -0,0 +1,227 @@
import os
import re
import shutil
import threading
import time
import uuid
from fastapi import APIRouter, HTTPException, Query
from pydantic import BaseModel
from core.export import ExportRunner
from core.paths import build_export_path, build_sequence_dir
from core.ffmpeg import _RATIOS, apply_keyframes_to_jobs
from .. import ws as ws_module
from ..config import EXPORT_DIR, MEDIA_DIRS
router = APIRouter()
_jobs: dict[str, dict] = {}
_counter_lock = threading.Lock()
_VALID_ENCODERS = {"libx264", "h264_nvenc", "h264_vaapi", "h264_qsv", "h264_amf", "h264_videotoolbox"}
_MAX_FINISHED_JOBS = 200
class CropKeyframe(BaseModel):
time: float
center: float
ratio: str | None = None
rand_portrait: bool = False
rand_square: bool = False
class ExportRequest(BaseModel):
input_path: str
cursor: float
name: str
clips: int = 3
spread: float = 3.0
short_side: int | None = None
portrait_ratio: str | None = None
crop_center: float = 0.5
format: str = "MP4"
label: str = ""
category: str = ""
profile: str = "default"
folder_suffix: str = ""
crop_keyframes: list[CropKeyframe] | None = None
rand_portrait: bool = False
rand_square: bool = False
encoder: str = "libx264"
def _next_counter(folder: str, basename: str) -> int:
"""Scan folder for existing {basename}_NNN dirs and return max + 1."""
pattern = re.compile(rf'^{re.escape(basename)}_(\d{{3}})$')
highest = 0
if os.path.isdir(folder):
for entry in os.listdir(folder):
m = pattern.match(entry)
if m:
highest = max(highest, int(m.group(1)))
return highest + 1
def _validate_input_path(path: str) -> str:
"""Verify input_path falls under a configured MEDIA_DIR."""
real = os.path.realpath(path)
for root in MEDIA_DIRS:
root_real = os.path.realpath(root)
if real == root_real or real.startswith(root_real + os.sep):
return real
raise HTTPException(status_code=403, detail="input_path outside media directories")
@router.post("/export")
def start_export(req: ExportRequest):
from ..app import db
# Validate inputs
input_path = _validate_input_path(req.input_path)
if req.encoder not in _VALID_ENCODERS:
raise HTTPException(status_code=400, detail=f"invalid encoder: {req.encoder}")
if req.portrait_ratio is not None and req.portrait_ratio not in _RATIOS:
raise HTTPException(status_code=400, detail=f"invalid portrait_ratio: {req.portrait_ratio}")
if req.folder_suffix and ("/" in req.folder_suffix or "\\" in req.folder_suffix or ".." in req.folder_suffix):
raise HTTPException(status_code=400, detail="folder_suffix must not contain path separators")
if "/" in req.name or "\\" in req.name or ".." in req.name:
raise HTTPException(status_code=400, detail="name must not contain path separators")
job_id = str(uuid.uuid4())[:8]
folder = EXPORT_DIR
if req.folder_suffix:
folder = folder.rstrip(os.sep) + "_" + req.folder_suffix
image_sequence = req.format in ("WebP", "WebP sequence")
# Lock counter + directory creation to prevent race between concurrent exports
with _counter_lock:
counter = _next_counter(folder, req.name)
jobs = []
for i in range(req.clips):
start = req.cursor + i * req.spread
if image_sequence:
out = build_sequence_dir(folder, req.name, counter, sub=i if req.clips > 1 else None)
else:
out = build_export_path(folder, req.name, counter, sub=i if req.clips > 1 else None)
os.makedirs(os.path.dirname(out), exist_ok=True)
jobs.append((start, out, req.portrait_ratio, req.crop_center))
# Apply keyframes if provided — returns 6-tuples, strip back to 4
if req.crop_keyframes:
kf_tuples = [
(kf.time, kf.center, kf.ratio, kf.rand_portrait, kf.rand_square)
for kf in req.crop_keyframes
]
widened = apply_keyframes_to_jobs(
jobs, kf_tuples,
req.crop_center, req.portrait_ratio,
req.rand_portrait, req.rand_square,
)
jobs = [(s, o, r, c) for s, o, r, c, _rp, _rs in widened]
completed = []
def on_clip_done(path: str):
completed.append(path)
# Record in DB so markers show up
db.add(
filename=os.path.basename(input_path),
start_time=req.cursor,
output_path=path,
label=req.label,
category=req.category,
short_side=req.short_side,
portrait_ratio=req.portrait_ratio or "",
crop_center=req.crop_center,
fmt=req.format,
clip_count=req.clips,
spread=req.spread,
profile=req.profile,
)
ws_module.broadcast({"type": "clip_done", "job_id": job_id, "path": path})
def on_all_done():
_jobs[job_id]["status"] = "done"
_jobs[job_id].pop("runner", None)
ws_module.broadcast({"type": "all_done", "job_id": job_id})
def on_error(msg: str):
_jobs[job_id]["status"] = "error"
_jobs[job_id]["error"] = msg
_jobs[job_id].pop("runner", None)
ws_module.broadcast({"type": "error", "job_id": job_id, "msg": msg})
runner = ExportRunner(
input_path=input_path,
jobs=jobs,
short_side=req.short_side,
image_sequence=image_sequence,
encoder=req.encoder,
on_clip_done=on_clip_done,
on_all_done=on_all_done,
on_error=on_error,
)
# Evict old finished jobs to prevent unbounded growth
finished = [k for k, v in _jobs.items() if v["status"] in ("done", "error")]
if len(finished) > _MAX_FINISHED_JOBS:
for k in finished[:len(finished) - _MAX_FINISHED_JOBS]:
del _jobs[k]
_jobs[job_id] = {
"status": "running",
"total": len(jobs),
"completed": completed,
"runner": runner,
"created_at": time.monotonic(),
}
runner.start()
return {"job_id": job_id}
@router.get("/export/{job_id}")
def get_export_status(job_id: str):
job = _jobs.get(job_id)
if job is None:
raise HTTPException(status_code=404, detail="job not found")
return {
"status": job["status"],
"total": job["total"],
"completed": len(job["completed"]),
"outputs": list(job["completed"]),
"error": job.get("error"),
}
def _is_under_export_dir(real_path: str) -> bool:
"""Check if path is under EXPORT_DIR or any EXPORT_DIR_suffix sibling."""
export_real = os.path.realpath(EXPORT_DIR).rstrip(os.sep)
# Walk up ancestors — must find EXPORT_DIR or EXPORT_DIR_suffix
d = os.path.dirname(real_path)
while d != os.path.dirname(d):
if d == export_real or d.startswith(export_real + "_"):
return True
d = os.path.dirname(d)
return False
@router.delete("/export")
def delete_export(output_path: str = Query(...)):
from ..app import db
real = os.path.realpath(output_path)
if not _is_under_export_dir(real):
raise HTTPException(status_code=403, detail="path outside export directory")
db.delete_by_output_path(real)
if os.path.isfile(real):
os.unlink(real)
elif os.path.isdir(real):
shutil.rmtree(real)
return {"deleted": real}
+56
View File
@@ -0,0 +1,56 @@
import os
from fastapi import APIRouter, HTTPException, Query
from fastapi.responses import FileResponse
from ..config import MEDIA_DIRS, VIDEO_EXTENSIONS
router = APIRouter()
def _scan_videos(root: str) -> list[dict]:
results = []
for dirpath, _, filenames in os.walk(root):
for f in sorted(filenames):
if os.path.splitext(f)[1].lower() in VIDEO_EXTENSIONS:
full = os.path.join(dirpath, f)
rel = os.path.relpath(full, root)
results.append({
"name": f,
"path": rel,
"root": root,
"size": os.path.getsize(full),
})
return results
@router.get("/files")
def list_files(root: str | None = Query(None)):
dirs = [root] if root and root in MEDIA_DIRS else MEDIA_DIRS
files = []
for d in dirs:
files.extend(_scan_videos(d))
return files
@router.get("/roots")
def list_roots():
return MEDIA_DIRS
def _safe_resolve(path: str, root: str) -> str:
"""Join path to root and verify it stays within the root directory."""
if root not in MEDIA_DIRS:
raise HTTPException(status_code=400, detail="invalid root")
full = os.path.realpath(os.path.join(root, path))
if not full.startswith(os.path.realpath(root) + os.sep):
raise HTTPException(status_code=403, detail="path outside media root")
return full
@router.get("/video/{path:path}")
def serve_video(path: str, root: str = Query(...)):
full = _safe_resolve(path, root)
if not os.path.isfile(full):
raise HTTPException(status_code=404, detail="not found")
return FileResponse(full, media_type="video/mp4")
+25
View File
@@ -0,0 +1,25 @@
from fastapi import APIRouter, Query
router = APIRouter()
def _db():
from ..app import db
return db
@router.post("/hidden/{filename}")
def hide_file(filename: str, profile: str = Query("default")):
_db().hide_file(filename, profile)
return {"hidden": filename}
@router.delete("/hidden/{filename}")
def unhide_file(filename: str, profile: str = Query("default")):
_db().unhide_file(filename, profile)
return {"unhidden": filename}
@router.get("/hidden")
def get_hidden(profile: str = Query("default")):
return sorted(_db().get_hidden_files(profile))
+27
View File
@@ -0,0 +1,27 @@
from fastapi import APIRouter, Query
router = APIRouter()
def _db():
from ..app import db
return db
@router.get("/markers/{filename}")
def get_markers(filename: str, profile: str = Query("default")):
markers = _db().get_markers(filename, profile)
return [
{"start_time": t, "marker_number": n, "output_path": p}
for t, n, p in markers
]
@router.get("/profiles")
def get_profiles():
return _db().get_profiles()
@router.get("/labels")
def get_labels():
return _db().get_labels()
+49
View File
@@ -0,0 +1,49 @@
import os
from fastapi import APIRouter, HTTPException, Query
from fastapi.responses import FileResponse, JSONResponse
from ..config import MEDIA_DIRS, QUALITY_PRESETS
from .. import cache
router = APIRouter()
def _resolve_source(path: str, root: str) -> str:
"""Join path to root, verify it stays within root, and exists."""
if root not in MEDIA_DIRS:
raise HTTPException(status_code=400, detail="invalid root")
full = os.path.realpath(os.path.join(root, path))
if not full.startswith(os.path.realpath(root) + os.sep):
raise HTTPException(status_code=403, detail="path outside media root")
if not os.path.isfile(full):
raise HTTPException(status_code=404, detail="not found")
return full
@router.get("/stream/{path:path}")
def stream_video(path: str, root: str = Query(...), quality: str = Query("low")):
if quality not in QUALITY_PRESETS:
raise HTTPException(status_code=400, detail=f"invalid quality: {quality}")
source = _resolve_source(path, root)
status = cache.ensure_transcode(source, quality)
if status == cache.CacheStatus.READY:
return FileResponse(cache.cache_path(source, quality), media_type="video/mp4")
return JSONResponse({"status": status, "quality": quality}, status_code=202)
@router.get("/audio/{path:path}")
def stream_audio(path: str, root: str = Query(...)):
source = _resolve_source(path, root)
status = cache.ensure_audio(source)
if status == cache.CacheStatus.READY:
return FileResponse(cache.audio_cache_path(source), media_type="audio/wav")
return JSONResponse({"status": status}, status_code=202)
@router.get("/cache/status/{path:path}")
def cache_status(path: str, root: str = Query(...)):
source = _resolve_source(path, root)
return cache.get_all_statuses(source)
+43
View File
@@ -0,0 +1,43 @@
import asyncio
import json
import threading
from fastapi import WebSocket, WebSocketDisconnect
_lock = threading.Lock()
_connections: list[WebSocket] = []
_loop: asyncio.AbstractEventLoop | None = None
async def connect(ws: WebSocket):
global _loop
_loop = asyncio.get_running_loop()
await ws.accept()
with _lock:
_connections.append(ws)
try:
while True:
await ws.receive_text() # keep alive
except (WebSocketDisconnect, Exception):
pass
finally:
with _lock:
if ws in _connections:
_connections.remove(ws)
def broadcast(msg: dict):
"""Send a message to all connected WebSocket clients.
Called from sync code (export callbacks running in background threads),
so we schedule sends on uvicorn's event loop.
"""
if _loop is None:
return
data = json.dumps(msg)
with _lock:
for ws in list(_connections):
try:
asyncio.run_coroutine_threadsafe(ws.send_text(data), _loop)
except Exception:
pass
+59
View File
@@ -0,0 +1,59 @@
# 8-cut Windows setup script
# Run once: powershell -ExecutionPolicy Bypass -File setup-windows.ps1
#
# Prerequisites: Python 3.10+ must be installed and on PATH
# https://www.python.org/downloads/
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
Write-Host "=== 8-cut Windows Setup ===" -ForegroundColor Cyan
# ── Python deps ────────────────────────────────────────────
Write-Host "`nInstalling Python dependencies..."
pip install PyQt6 python-mpv
# ── libmpv ─────────────────────────────────────────────────
$mpvDll = Join-Path $root "libmpv-2.dll"
if (Test-Path $mpvDll) {
Write-Host "`nlibmpv-2.dll already present, skipping." -ForegroundColor Green
} else {
Write-Host "`nDownloading libmpv..."
$release = Invoke-RestMethod "https://api.github.com/repos/shinchiro/mpv-winbuild-cmake/releases/latest"
$asset = $release.assets | Where-Object { $_.name -like "mpv-dev-x86_64-v3-*" } | Select-Object -First 1
$tmpFile = Join-Path $root "mpv-dev.7z"
Invoke-WebRequest $asset.browser_download_url -OutFile $tmpFile
7z x $tmpFile -o"$root\mpv-dev" -y | Out-Null
Copy-Item "$root\mpv-dev\libmpv-2.dll" $root
Remove-Item $tmpFile -Force
Remove-Item "$root\mpv-dev" -Recurse -Force
Write-Host "libmpv-2.dll downloaded." -ForegroundColor Green
}
# ── ffmpeg ─────────────────────────────────────────────────
$ffmpeg = Join-Path $root "ffmpeg.exe"
if (Test-Path $ffmpeg) {
Write-Host "`nffmpeg.exe already present, skipping." -ForegroundColor Green
} else {
# Check if ffmpeg is on PATH
$onPath = Get-Command ffmpeg -ErrorAction SilentlyContinue
if ($onPath) {
Write-Host "`nffmpeg found on PATH: $($onPath.Source)" -ForegroundColor Green
} else {
Write-Host "`nDownloading ffmpeg..."
$ffUrl = "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
$tmpZip = Join-Path $root "ffmpeg.zip"
Invoke-WebRequest $ffUrl -OutFile $tmpZip
Expand-Archive $tmpZip -DestinationPath "$root\ffmpeg-tmp" -Force
$bin = Get-ChildItem -Path "$root\ffmpeg-tmp" -Recurse -Filter ffmpeg.exe | Select-Object -First 1
Copy-Item "$($bin.DirectoryName)\ffmpeg.exe" $root
Copy-Item "$($bin.DirectoryName)\ffprobe.exe" $root
Remove-Item $tmpZip -Force
Remove-Item "$root\ffmpeg-tmp" -Recurse -Force
Write-Host "ffmpeg.exe downloaded." -ForegroundColor Green
}
}
Write-Host "`n=== Setup complete ===" -ForegroundColor Cyan
Write-Host "Run 8-cut with: python main.py"
Write-Host "Or double-click: 8cut.bat"
+208 -58
View File
@@ -1,16 +1,24 @@
import tempfile, os, json
from main import build_export_path, format_time, build_ffmpeg_command, build_mask_output_dir, build_sequence_dir, build_audio_extract_command, build_annotation_json_path, upsert_clip_annotation
from main import _normalize_filename, ProcessedDB
from main import build_export_path, format_time, build_ffmpeg_command, build_sequence_dir, build_audio_extract_command, build_annotation_json_path, upsert_clip_annotation, resolve_keyframe, apply_keyframes_to_jobs
from main import ProcessedDB
def test_build_export_path_first():
assert build_export_path("/out", "clip", 1) == "/out/clip_001.mp4"
assert build_export_path("/out", "clip", 1) == "/out/clip_001/clip_001.mp4"
def test_build_export_path_counter():
assert build_export_path("/out", "clip", 42) == "/out/clip_042.mp4"
assert build_export_path("/out", "clip", 42) == "/out/clip_042/clip_042.mp4"
def test_build_export_path_deep_counter():
assert build_export_path("/out", "shot", 999) == "/out/shot_999.mp4"
assert build_export_path("/out", "shot", 999) == "/out/shot_999/shot_999.mp4"
def test_build_export_path_sub():
assert build_export_path("/out", "clip", 1, sub=0) == "/out/clip_001/clip_001_0.mp4"
assert build_export_path("/out", "clip", 1, sub=2) == "/out/clip_001/clip_001_2.mp4"
def test_build_sequence_dir_sub():
assert build_sequence_dir("/out", "clip", 1, sub=0) == "/out/clip_001/clip_001_0"
assert build_sequence_dir("/out", "clip", 1, sub=1) == "/out/clip_001/clip_001_1"
def test_format_time_seconds():
assert format_time(0.0) == "0:00.0"
@@ -45,63 +53,47 @@ def test_ffmpeg_command_with_resize():
assert cmd[-1] == "/out/clip_001.mp4"
# --- _normalize_filename ---
def test_normalize_strips_extension():
assert _normalize_filename("clip.mp4") == "clip"
def test_normalize_strips_resolution():
assert _normalize_filename("clip_2160p.mp4") == "clip"
def test_normalize_strips_1080p():
assert _normalize_filename("clip_1080p.mkv") == "clip"
def test_normalize_strips_multiple_tags():
assert _normalize_filename("show_1080p_HDR.mkv") == "show"
def test_normalize_lowercases():
assert _normalize_filename("MyVideo_4K.mp4") == "myvideo"
def test_normalize_collapses_separators():
assert _normalize_filename("my__video--2160p.mp4") == "my_video"
# --- ProcessedDB ---
def test_db_add_and_find_exact():
def test_db_add_and_get_markers():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
path = f.name
try:
db = ProcessedDB(path)
db.add("video.mp4", 12.5, "/out/clip_001.mp4")
assert db.find_similar("video.mp4") == "video.mp4"
markers = db.get_markers("video.mp4")
assert len(markers) == 1
assert markers[0][0] == 12.5
finally:
os.unlink(path)
def test_db_find_similar_resolution_variant():
def test_db_exact_match_only():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
path = f.name
try:
db = ProcessedDB(path)
db.add("episode_s01e01_2160p.mkv", 0.0, "/out/ep_001.mp4")
assert db.find_similar("episode_s01e01_1080p.mkv") == "episode_s01e01_2160p.mkv"
# Different filename — no match even if similar
assert db.get_markers("episode_s01e01_1080p.mkv") == []
# Exact filename — match
assert len(db.get_markers("episode_s01e01_2160p.mkv")) == 1
finally:
os.unlink(path)
def test_db_find_similar_no_match():
def test_db_no_match():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
path = f.name
try:
db = ProcessedDB(path)
db.add("alpha.mp4", 0.0, "/out/alpha_001.mp4")
assert db.find_similar("completely_different_zzzz.mp4") is None
assert db.get_markers("completely_different.mp4") == []
finally:
os.unlink(path)
def test_db_disabled_survives_bad_path():
db = ProcessedDB("/no/such/directory/8cut.db")
db.add("x.mp4", 0.0, "/out/x_001.mp4") # must not raise
assert db.find_similar("x.mp4") is None
assert db.get_markers("x.mp4") == []
def test_db_get_markers_returns_sorted():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
@@ -119,19 +111,6 @@ def test_db_get_markers_returns_sorted():
finally:
os.unlink(path)
def test_db_get_markers_fuzzy_match():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
path = f.name
try:
db = ProcessedDB(path)
db.add("show_2160p.mkv", 5.0, "/out/s_001.mp4")
markers = db.get_markers("show_1080p.mkv")
assert len(markers) == 1
assert markers[0][0] == 5.0
assert markers[0][2] == "/out/s_001.mp4"
finally:
os.unlink(path)
def test_db_get_markers_no_match():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
path = f.name
@@ -174,16 +153,6 @@ def test_ffmpeg_command_portrait_off():
cmd = build_ffmpeg_command("/in/video.mp4", 0.0, "/out/clip.mp4")
assert "-vf" not in cmd
def test_mask_output_dir_basic():
assert build_mask_output_dir("/out/clip_001.mp4") == "/out/clip_001_masks"
def test_mask_output_dir_mkv():
assert build_mask_output_dir("/out/my_clip.mkv") == "/out/my_clip_masks"
def test_mask_output_dir_nested():
assert build_mask_output_dir("/a/b/c/shot_042.mp4") == "/a/b/c/shot_042_masks"
# --- build_audio_extract_command ---
def test_audio_extract_output_path():
@@ -208,10 +177,10 @@ def test_audio_extract_timing():
def test_build_sequence_dir_basic():
assert build_sequence_dir("/out", "clip", 1) == "/out/clip_001"
assert build_sequence_dir("/out", "clip", 1) == "/out/clip_001/clip_001"
def test_build_sequence_dir_counter():
assert build_sequence_dir("/out", "clip", 42) == "/out/clip_042"
assert build_sequence_dir("/out", "clip", 42) == "/out/clip_042/clip_042"
def test_ffmpeg_command_image_sequence():
cmd = build_ffmpeg_command("/in/v.mp4", 0.0, "/out/seq_001", image_sequence=True)
@@ -288,3 +257,184 @@ def test_db_stores_label_and_category():
assert row == ("dog barking", "Animal")
finally:
os.unlink(path)
def test_db_get_group_returns_all_sub_clips():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
path = f.name
try:
db = ProcessedDB(path)
db.add("video.mp4", 10.0, "/out/clip_001/clip_001_0.mp4")
db.add("video.mp4", 10.0, "/out/clip_001/clip_001_1.mp4")
db.add("video.mp4", 10.0, "/out/clip_001/clip_001_2.mp4")
group = db.get_group("/out/clip_001/clip_001_0.mp4")
assert len(group) == 3
assert "/out/clip_001/clip_001_0.mp4" in group
assert "/out/clip_001/clip_001_2.mp4" in group
finally:
os.unlink(path)
def test_db_get_group_isolates_by_start_time():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
path = f.name
try:
db = ProcessedDB(path)
db.add("video.mp4", 10.0, "/out/clip_001/clip_001_0.mp4")
db.add("video.mp4", 10.0, "/out/clip_001/clip_001_1.mp4")
db.add("video.mp4", 30.0, "/out/clip_002/clip_002_0.mp4")
group = db.get_group("/out/clip_001/clip_001_0.mp4")
assert len(group) == 2
finally:
os.unlink(path)
def test_db_delete_group_removes_all():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
path = f.name
try:
db = ProcessedDB(path)
db.add("video.mp4", 10.0, "/out/clip_001/clip_001_0.mp4")
db.add("video.mp4", 10.0, "/out/clip_001/clip_001_1.mp4")
db.add("video.mp4", 30.0, "/out/clip_002/clip_002_0.mp4")
deleted = db.delete_group("/out/clip_001/clip_001_0.mp4")
assert len(deleted) == 2
# clip_002 should still exist
markers = db.get_markers("video.mp4")
assert len(markers) == 1
assert markers[0][0] == 30.0
finally:
os.unlink(path)
def test_db_get_group_disabled():
db = ProcessedDB("/no/such/directory/8cut.db")
assert db.get_group("/out/clip_001.mp4") == []
def test_db_delete_group_disabled():
db = ProcessedDB("/no/such/directory/8cut.db")
assert db.delete_group("/out/clip_001.mp4") == []
# --- Profiles ---
def test_db_markers_isolated_by_profile():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
path = f.name
try:
db = ProcessedDB(path)
db.add("video.mp4", 10.0, "/out/a_001.mp4", profile="landscape")
db.add("video.mp4", 20.0, "/out/b_001.mp4", profile="portrait")
land = db.get_markers("video.mp4", profile="landscape")
port = db.get_markers("video.mp4", profile="portrait")
assert len(land) == 1
assert land[0][0] == 10.0
assert len(port) == 1
assert port[0][0] == 20.0
finally:
os.unlink(path)
def test_db_get_profiles():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
path = f.name
try:
db = ProcessedDB(path)
assert db.get_profiles() == []
db.add("a.mp4", 0.0, "/out/a.mp4", profile="beta")
db.add("b.mp4", 0.0, "/out/b.mp4", profile="alpha")
db.add("c.mp4", 0.0, "/out/c.mp4", profile="beta")
profiles = db.get_profiles()
assert profiles == ["alpha", "beta"]
finally:
os.unlink(path)
def test_db_get_profiles_disabled():
db = ProcessedDB("/no/such/directory/8cut.db")
assert db.get_profiles() == []
def test_db_default_profile_backward_compat():
"""Existing tests pass without explicit profile — defaults to 'default'."""
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
path = f.name
try:
db = ProcessedDB(path)
db.add("video.mp4", 5.0, "/out/clip.mp4")
markers = db.get_markers("video.mp4") # no profile arg
assert len(markers) == 1
assert markers[0][0] == 5.0
assert db.get_profiles() == ["default"]
finally:
os.unlink(path)
# --- resolve_keyframe ---
def test_resolve_keyframe_empty():
assert resolve_keyframe([], 5.0) is None
def test_resolve_keyframe_before_first():
kfs = [(3.0, 0.5, None, False, False)]
assert resolve_keyframe(kfs, 1.0) is None
def test_resolve_keyframe_exact():
kfs = [(2.0, 0.3, "9:16", True, False)]
assert resolve_keyframe(kfs, 2.0) == (2.0, 0.3, "9:16", True, False)
def test_resolve_keyframe_between():
kfs = [
(1.0, 0.2, None, False, False),
(5.0, 0.8, "1:1", False, True),
]
assert resolve_keyframe(kfs, 3.0) == (1.0, 0.2, None, False, False)
def test_resolve_keyframe_after_last():
kfs = [
(1.0, 0.2, None, False, False),
(5.0, 0.8, "1:1", False, True),
]
assert resolve_keyframe(kfs, 10.0) == (5.0, 0.8, "1:1", False, True)
def test_resolve_keyframe_tolerance():
kfs = [(4.0, 0.5, None, True, True)]
assert resolve_keyframe(kfs, 3.96) == (4.0, 0.5, None, True, True)
# --- apply_keyframes_to_jobs ---
def test_apply_keyframes_no_keyframes():
jobs = [(0.0, "/out/a", None, 0.5), (3.0, "/out/b", None, 0.5)]
result = apply_keyframes_to_jobs(jobs, [], base_center=0.5, base_ratio=None,
base_rand_p=True, base_rand_s=False)
assert result == [
(0.0, "/out/a", None, 0.5, True, False),
(3.0, "/out/b", None, 0.5, True, False),
]
def test_apply_keyframes_with_keyframes():
kfs = [
(0.0, 0.3, "9:16", True, False),
(4.0, 0.7, None, False, True),
]
jobs = [
(0.0, "/out/a", None, 0.5),
(3.0, "/out/b", None, 0.5),
(6.0, "/out/c", None, 0.5),
]
result = apply_keyframes_to_jobs(jobs, kfs, base_center=0.5, base_ratio=None,
base_rand_p=False, base_rand_s=False)
assert result == [
(0.0, "/out/a", "9:16", 0.3, True, False),
(3.0, "/out/b", "9:16", 0.3, True, False),
(6.0, "/out/c", None, 0.7, False, True),
]
def test_apply_keyframes_before_first_uses_base():
kfs = [(5.0, 0.8, "1:1", False, True)]
jobs = [(1.0, "/out/a", None, 0.5)]
result = apply_keyframes_to_jobs(jobs, kfs, base_center=0.5, base_ratio="4:5",
base_rand_p=True, base_rand_s=False)
assert result == [(1.0, "/out/a", "4:5", 0.5, True, False)]
-75
View File
@@ -1,75 +0,0 @@
"""Depth Anything V2 mask generation script.
Usage:
python tools/depth_masks.py --input video.mp4 --output masks_dir/
Outputs one binary PNG per frame: frame_0000.png, frame_0001.png, …
Foreground = white (255), background = black (0), via Otsu threshold on depth map.
Requires: torch, transformers, opencv-python, Pillow
"""
import argparse
import os
import sys
import cv2
import numpy as np
from PIL import Image
from transformers import pipeline
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--input", required=True)
parser.add_argument("--output", required=True)
args = parser.parse_args()
os.makedirs(args.output, exist_ok=True)
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using device: {device}", flush=True)
pipe = pipeline(
"depth-estimation",
model="depth-anything/Depth-Anything-V2-Large-hf",
device=device,
)
cap = cv2.VideoCapture(args.input)
if not cap.isOpened():
print(f"ERROR: cannot open {args.input}", file=sys.stderr)
sys.exit(1)
total = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
idx = 0
while True:
ret, frame = cap.read()
if not ret:
break
pil_img = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
result = pipe(pil_img)
depth = np.array(result["depth"]) # float32 array
# Normalise to 0255
d_min, d_max = depth.min(), depth.max()
if d_max > d_min:
depth_u8 = ((depth - d_min) / (d_max - d_min) * 255).astype(np.uint8)
else:
depth_u8 = np.zeros_like(depth, dtype=np.uint8)
# Otsu threshold: closer objects (higher depth value) = foreground
_, mask = cv2.threshold(depth_u8, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
out_path = os.path.join(args.output, f"frame_{idx:04d}.png")
cv2.imwrite(out_path, mask)
idx += 1
print(f"frame {idx}/{total}", flush=True)
cap.release()
print("done", flush=True)
if __name__ == "__main__":
main()
-83
View File
@@ -1,83 +0,0 @@
"""SAM2 mask generation script.
Usage:
python tools/sam_masks.py --input video.mp4 --output masks_dir/
Outputs one binary PNG per frame: frame_0000.png, frame_0001.png, …
Uses center of first frame as positive point prompt, propagates across all frames.
Requires: torch, segment-anything-2, opencv-python
"""
import argparse
import os
import sys
import tempfile
import cv2
import numpy as np
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--input", required=True)
parser.add_argument("--output", required=True)
args = parser.parse_args()
os.makedirs(args.output, exist_ok=True)
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using device: {device}", flush=True)
# Extract frames to temp directory (SAM2 video predictor needs image files)
with tempfile.TemporaryDirectory() as frame_dir:
cap = cv2.VideoCapture(args.input)
if not cap.isOpened():
print(f"ERROR: cannot open {args.input}", file=sys.stderr)
sys.exit(1)
total = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
idx = 0
while True:
ret, frame = cap.read()
if not ret:
break
cv2.imwrite(os.path.join(frame_dir, f"{idx:04d}.jpg"), frame)
idx += 1
cap.release()
print(f"Extracted {idx} frames", flush=True)
# SAM2: use from_pretrained (SAM2.1+ / HuggingFace integration)
from sam2.sam2_video_predictor import SAM2VideoPredictor
predictor = SAM2VideoPredictor.from_pretrained(
"facebook/sam2-hiera-large"
).to(device)
with torch.inference_mode():
state = predictor.init_state(video_path=frame_dir)
# Center of first frame as positive point prompt
cx, cy = width // 2, height // 2
_, _, _ = predictor.add_new_points_or_box(
inference_state=state,
frame_idx=0,
obj_id=1,
points=np.array([[cx, cy]], dtype=np.float32),
labels=np.array([1], dtype=np.int32),
)
for frame_idx, obj_ids, out_mask_logits in predictor.propagate_in_video(state):
# out_mask_logits: (N_objects, 1, H, W) — threshold logits at 0
mask = (out_mask_logits[0].squeeze().cpu().numpy() > 0.0).astype(np.uint8) * 255
out_path = os.path.join(args.output, f"frame_{frame_idx:04d}.png")
cv2.imwrite(out_path, mask)
print(f"frame {frame_idx + 1}/{total}", flush=True)
print("done", flush=True)
if __name__ == "__main__":
main()