feat(media): video versions: still frame + a version every screen plays (platform-v2 5.4e)

- services/video.py: background worker (one video at a time, low priority) makes a still
  frame (thumb/card/full WebP) and, when needed, play.mp4 (H.264+AAC, <=1920 px, HDR
  tone-mapped, faststart); the original is kept. Media.processing/progress (migration 0031,
  existing videos queued). ffmpeg from the pinned imageio-ffmpeg wheel; none = as uploaded.
- MOV (video/quicktime) accepted; /api/media/file/<sha>/play served with ranges.
- Signage plays the version (poster = still frame) and tells the screens playing it when ready.
- Manager library: still frames in the grid, preparing progress, status in the details.
- Tests: test_video.py (8), backend 541 passed; e2e media/signage/stack new checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 02:10:22 +02:00
co-authored by Claude Opus 5.5
parent f8d0d29d8f
commit b5361e10ca
28 changed files with 756 additions and 39 deletions
+12 -4
View File
@@ -6,8 +6,9 @@
GET /api/media/{id} one item, with what uses it
PATCH /api/media/{id} rename
DELETE /api/media/{id} refused with `media.in_use` while something uses it
GET /api/media/file/{sha}/{variant} the bytes: thumb | card | full (images, WebP)
| original. Public (LAN, like the customer display's
GET /api/media/file/{sha}/{variant} the bytes: thumb | card | full (WebP: a picture,
or a video's still frame) | original | play (a video's
version every screen plays, step 5.4e). Public (LAN, like the customer display's
images), cached for a year: a URL never changes meaning.
Whoever manages the menu, the customer display, signage or the menu tablets manages the
@@ -30,6 +31,7 @@ from database import get_db
from datetime import datetime
from models.media import Media
from services import media as store
from services import video
router = APIRouter()
MANAGE = ("catalog.menu.manage", "customer_display.manage", "signage.manage", "menu_tablet.manage")
@@ -53,6 +55,8 @@ class MediaOut(BaseModel):
uploaded_by_name: Optional[str] = None
created_at: datetime
builtin: bool = False
processing: Optional[str] = None # videos: waiting | working | done | failed (5.4e)
progress: Optional[int] = None
urls: dict = Field(default_factory=dict)
@@ -131,6 +135,8 @@ def upload_media(response: Response, file: UploadFile = File(...), name: Optiona
info = store.ingest(tmp, sha, size)
item = Media(name=(name or "").strip()[:120] or _name_from(file.filename),
original_name=(file.filename or None), sha256=sha, bytes=size, uploaded_by=user.id, **info)
if item.kind == "video":
video.queued(item) # its still frame and playable version, in the background
try:
db.add(item)
db.commit()
@@ -138,6 +144,8 @@ def upload_media(response: Response, file: UploadFile = File(...), name: Optiona
store.delete_files(sha)
raise
db.refresh(item)
if item.processing:
video.wake()
return _out(item, UploadOut)
@@ -149,10 +157,10 @@ def media_file(sha: str, variant: str, request: Request, db: Session = Depends(g
path = store.ensure_variant(item, variant) if item is not None else None
if not path or not os.path.exists(path):
raise XeniaError("media.not_found", media_id=sha)
ctype = item.content_type if variant == "original" else "image/webp"
ctype = item.content_type if variant == "original" else "video/mp4" if variant == "play" else "image/webp"
headers = {"Cache-Control": CACHE, "Accept-Ranges": "bytes"}
rng = request.headers.get("range")
if rng and variant == "original":
if rng and variant in ("original", "play"):
return _ranged(path, ctype, rng, headers)
return FileResponse(path, media_type=ctype, headers=headers)