Skip to content

feat: video → WebM conversion with S3 hash cache + per-job build report (0.3.0) - #3

Merged
driedel merged 4 commits into
mainfrom
feat/job-report
Nov 25, 2026
Merged

driedel merged 4 commits into
mainfrom
feat/job-report

Conversation

@driedel

@driedel driedel commented Nov 25, 2026

Copy link
Copy Markdown
Owner

What's in this release

Video optimization (feat(worker), e732545)

  • Worker image ships ffmpeg; optimize.py converts non-web videos (.mov/.m4v/.avi/.mkv/.wmv/.mpg/.mpeg) to WebM (VP9 + Opus), replacing originals and rewriting refs — same model as images (AVIF) and fonts (WOFF2)
  • S3 hash cache: converted .webm objects carry source-sha256 + encoder metadata, so repeat deploys of an unchanged video skip ffmpeg entirely
  • Upload skip: sync_to_s3 stores per-file sha256 in object metadata and skips unchanged uploads
  • New convert_videos option (default true); RQ job timeout 600s → 1800s

Per-job build report (feat(worker), abeb08b)

  • optimize.py --report writes per-file entries ({path, kind, action, original_bytes, final_bytes, sources?}; actions: converted|bundled|minified|cached)
  • jobs.py aggregates a report key into the job result: pages, per-type original/final bytes, totals with saved_pct, steps_seconds, top_savings (≤10) — consumed by the WordPress plugin jobs screen

Docs (206cde8)

  • README documents the report key, video cache and 30-min job timeout; AGENTS.md updated; FastAPI version aligned to 0.3.0

Validation

  • pytest 150 passed, pylint 10.00/10 (Docker)
  • E2E (POC): .mov 29.9 MB → .webm 11.2 MB (−62.4%); 2nd deploy with cache: optimize step −63.6%

Video conversion:
- The worker image now ships ffmpeg; optimize.py converts non-web video
  formats (.mov/.m4v/.avi/.mkv/.wmv/.mpg/.mpeg, case-insensitive) to WebM
  (VP9 CRF 33 + Opus 96k), replacing the original file and rewriting
  references — the same model already used for images (AVIF) and fonts
  (WOFF2). .mp4 is left untouched (already web-friendly).
- Per-file ffmpeg timeout of 600s; failures keep the original and only
  warn, so the pipeline never breaks on a bad video.
- New convert_videos option (default true) flowing from the API payload
  through jobs.py to optimize.py's --no-convert-videos flag.

S3 hash cache (deploy speed):
- sync_to_s3 stores each file's sha256 in the object metadata and skips
  re-uploading unchanged files (HEAD per file; metadata instead of ETag
  because multipart uploads make the ETag a composite value).
- Converted .webm objects additionally carry source-sha256 and an encoder
  tag, so repeat deploys of an unchanged video skip the ffmpeg run
  entirely — the existing .webm in S3 is reused.
- The RQ job timeout goes from 600s to 1800s so the first (uncached)
  deploy of video-heavy pages fits scrape + encoding.

Also adds deterministic Content-Types for video extensions in deploy.py,
13 new tests (video conversion, cache hit/miss, upload skip, option
wiring), and README/AGENTS.md updates.
optimize.py gains an optional --report <path.json> flag that records every
file the pipeline touches ({path, kind, action, original_bytes, final_bytes,
sources?} — actions: converted|bundled|minified|cached). jobs.py snapshots
the workdir after postprocess (the 'original' side), times each pipeline
step (time.monotonic), and aggregates a 'report' key into the job result:
pages, per-asset-type original/final bytes, video converted/cache_hits
counts, totals with saved_pct, steps_seconds, and the top 10 savings.
deploy.py excludes the .build-report.json artifact from the S3 upload,
following the video cache manifest pattern.

The WordPress plugin renders this report on the jobs screen.
- README: GET /jobs/{id} result example now shows files_skipped and the
  full report key (pages, per-type assets with original/final bytes,
  video converted/cache_hits, totals with saved_pct, steps_seconds,
  top_savings); notes the 30-minute job timeout.
- AGENTS.md: optimize.py CLI gains --report/--cache-bucket/--cache-prefix;
  documents the internal artifacts never uploaded to S3
  (.video-cache-manifest.json, .build-report.json).
- api/main.py: FastAPI app version aligned with the release (0.3.0).
The two S3 video-cache tests mock subprocess.run but not the
shutil.which('ffmpeg') guard, so they only passed where a real ffmpeg
binary exists (the worker image) and failed on the CI runner, which has
none. Patch optimize.shutil.which so the tests are environment-independent.
@driedel
driedel merged commit 3478cd0 into main Nov 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant