Compare commits

...
8 Commits
Author SHA1 Message Date
yiling 29cd5d807c test(scripts): find release by version in changelog integration test 2026-09-24 20:34:53 +08:00
yiling f6e27095a5 Release v0.4.8 2026-09-24 20:26:23 +08:00
Yiling-J 55637bc9a8 feat(transcode): optimize video proxy quality and fix videotoolbox first-frame blocking (#426)
- Fix first-frame macroblocking on VideoToolbox hardware acceleration by avoiding -maxrate/-bufsize which triggers Apple's DataRateLimits initial rate controller starvation, applying target -b:v instead.
- Optimize software encoding (libx264) quality by adjusting CRF from 26 to 23.
- Disable B-frames (-bf 0) for libx264 proxies to ensure zero-latency frame stepping (JKL) and scrubbing, matching Frame.io review proxy standards.
- Update unit tests to verify the new encoder configurations and bitrate calculation logic.
2026-09-24 17:16:02 +08:00
Yiling-J 0d6671c3e1 fix(webui): show play button and darken tint only before initial playback (#425)
* fix(webui): remove paused play button overlay and darken cover from video players

* fix(webui): show play button and darken tint only before initial playback
2026-09-24 15:19:46 +08:00
Yiling-J c3375ee935 feat(transcode): add HDR video proxy support and playback (#424)
* feat(transcode): add HDR output proxy support

* fix(transcode): auto-detect MoltenVK Vulkan ICD on macOS for libplacebo filters

* fix(transcode): split filter in generateSprite to ensure poster uses tone-mapped stream

* docs(changelog): update docs/changelog.mdx and ignore in prettier

* fix(transcode): respect video rotation metadata to preserve display aspect ratio

* fix(webui): render native video with hardware EDR acceleration instead of 2D canvas

* fix(webui): show HDR label on mobile video control bar

* fix(share): preserve hdr flag on watermarked video transcodes

* fix(webui): differentiate HDR download options in video player

* fix(transcode): handle Dolby Vision Profile 5 via standard HDR pipeline without libplacebo

* fix(transcode): prepend setparams filter to prevent zscale colorspace path error for DV P5

* refactor(transcode): simplify HDR proxies to always produce HDR without SDR setting
2026-09-24 14:32:47 +08:00
Yiling-J f579947770 feat(docs): add changelog section to mintlify documentation (#422) 2026-09-22 21:02:27 +08:00
Yiling-J 53c9485f10 fix(core): only manage PID files in daemon mode (#421) 2026-09-22 20:31:38 +08:00
Yiling-J 75bf9b3b88 fix(docker): stop publishing postgres port in compose files (#420)
The bundled PostgreSQL service published port 5432 on the host, which caused
docker compose up to fail when that port was already in use. A failed start
leaves the container without a network endpoint, so subsequent runs reuse the
broken container and the app cannot reach the database (Prisma P1001).

The app only needs the database inside the compose network, so the host port
mapping is unnecessary. Remove it from all local and temporal compose files.
2026-09-20 11:46:13 +08:00
65 changed files with 3447 additions and 270 deletions
+2 -1
View File
@@ -7,4 +7,5 @@ packages/core/src/generated
src/ui/components/ui
packages/webui/paraglide
*.md
**/*.md
**/*.md
docs/changelog.mdx
+18
View File
@@ -12,6 +12,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Changed
## [0.4.8] - 2026-09-24
### Added
- **transcode**: Add HDR video proxy support: HDR videos automatically generate HDR video proxies and preview videos preserving HDR color characteristics, tone-mapped SDR thumbnails and posters, and automatic HDR player playback on supported displays with hardware EDR acceleration
- **docs**: Add a Changelog section to the documentation site so users can explore release notes and updates directly in Mintlify
### Fixed
- **webui**: Only show the center play button and darkened tint on initial video open before playback starts; once played, pausing or scrubbing back to start keeps the video canvas clean and unobstructed for review
- **transcode**: Fix an issue where videos with orientation or rotation metadata (such as smartphone vertical videos) were incorrectly displayed with stretched aspect ratios in the video player
- **cli**: Only manage and check PID files in daemon mode, preventing stale PID files, crash-loop conflicts, or spurious process checks during normal foreground and Docker execution
### Changed
- **transcode**: Improve video proxy visual quality and disable B-frames for smoother frame-by-frame seeking and scrubbing
## [0.4.7] - 2026-09-19
### Added
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/agent-app",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/cli",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/premiere-uxp",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "commonjs",
"scripts": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/transcode-app",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/web-app",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"dependencies": {
+15 -15
View File
@@ -33,7 +33,7 @@
},
"apps/agent": {
"name": "@shumai/agent-app",
"version": "0.4.7",
"version": "0.4.8",
"bin": {
"shumai-agent": "./src/index.ts",
},
@@ -45,7 +45,7 @@
},
"apps/cli": {
"name": "@shumai/cli",
"version": "0.4.7",
"version": "0.4.8",
"bin": {
"shumai-cli": "./src/index.ts",
},
@@ -60,7 +60,7 @@
},
"apps/premiere-uxp": {
"name": "@shumai/premiere-uxp",
"version": "0.4.7",
"version": "0.4.8",
"dependencies": {
"@shumai/api": "workspace:*",
"@shumai/dtos": "workspace:*",
@@ -114,7 +114,7 @@
},
"apps/transcode": {
"name": "@shumai/transcode-app",
"version": "0.4.7",
"version": "0.4.8",
"bin": {
"shumai-transcode": "./src/index.ts",
},
@@ -126,7 +126,7 @@
},
"apps/web": {
"name": "@shumai/web-app",
"version": "0.4.7",
"version": "0.4.8",
"dependencies": {
"@shumai/agent": "workspace:*",
"@shumai/api": "workspace:*",
@@ -146,7 +146,7 @@
},
"packages/agent": {
"name": "@shumai/agent",
"version": "0.4.7",
"version": "0.4.8",
"dependencies": {
"@anthropic-ai/sandbox-runtime": "0.0.74",
"@earendil-works/pi-agent-core": "0.82.1",
@@ -171,7 +171,7 @@
},
"packages/api": {
"name": "@shumai/api",
"version": "0.4.7",
"version": "0.4.8",
"dependencies": {
"@hono/zod-validator": "0.7.6",
"@shumai/core": "workspace:*",
@@ -185,7 +185,7 @@
},
"packages/core": {
"name": "@shumai/core",
"version": "0.4.7",
"version": "0.4.8",
"dependencies": {
"@ai-sdk/alibaba": "2.0.38",
"@ai-sdk/amazon-bedrock": "5.0.67",
@@ -242,7 +242,7 @@
},
"packages/db": {
"name": "@shumai/db",
"version": "0.4.7",
"version": "0.4.8",
"dependencies": {
"@earendil-works/pi-agent-core": "0.82.1",
"@prisma/adapter-pg": "7.10.0",
@@ -258,7 +258,7 @@
},
"packages/dtos": {
"name": "@shumai/dtos",
"version": "0.4.7",
"version": "0.4.8",
"dependencies": {
"@earendil-works/pi-agent-core": "0.82.1",
"zod": "4.5.4",
@@ -266,7 +266,7 @@
},
"packages/e2e": {
"name": "@shumai/e2e",
"version": "0.4.7",
"version": "0.4.8",
"dependencies": {
"@earendil-works/pi-agent-core": "0.82.1",
"@google/genai": "2.19.0",
@@ -281,11 +281,11 @@
},
"packages/tableprinter": {
"name": "@shumai/tableprinter",
"version": "0.4.7",
"version": "0.4.8",
},
"packages/transcode": {
"name": "@shumai/transcode",
"version": "0.4.7",
"version": "0.4.8",
"dependencies": {
"@shumai/core": "workspace:*",
"@shumai/db": "workspace:*",
@@ -299,7 +299,7 @@
},
"packages/webui": {
"name": "@shumai/webui",
"version": "0.4.7",
"version": "0.4.8",
"dependencies": {
"@base-ui/react": "1.7.0",
"@dnd-kit/abstract": "0.5.0",
@@ -401,7 +401,7 @@
},
"packages/workflow-core": {
"name": "@shumai/workflow-core",
"version": "0.4.7",
"version": "0.4.8",
"dependencies": {
"@shumai/core": "workspace:*",
"@shumai/db": "workspace:*",
@@ -6,8 +6,6 @@ services:
POSTGRES_USER: shumai
POSTGRES_PASSWORD: shumai_password
POSTGRES_DB: shumai_db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/18/docker
healthcheck:
-2
View File
@@ -6,8 +6,6 @@ services:
POSTGRES_USER: shumai
POSTGRES_PASSWORD: shumai_password
POSTGRES_DB: shumai_db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/18/docker
healthcheck:
@@ -7,8 +7,6 @@ services:
POSTGRES_USER: shumai
POSTGRES_PASSWORD: shumai_password
POSTGRES_DB: shumai_db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql
healthcheck:
+817
View File
@@ -0,0 +1,817 @@
---
title: "Changelog"
description: "Recent updates, new features, and improvements in Shumai"
---
<Update label="v0.4.8" description="September 24, 2026">
### Added
- **transcode**: Add HDR video proxy support: HDR videos automatically generate HDR video proxies and preview videos preserving HDR color characteristics, tone-mapped SDR thumbnails and posters, and automatic HDR player playback on supported displays with hardware EDR acceleration
- **docs**: Add a Changelog section to the documentation site so users can explore release notes and updates directly in Mintlify
### Fixed
- **webui**: Only show the center play button and darkened tint on initial video open before playback starts; once played, pausing or scrubbing back to start keeps the video canvas clean and unobstructed for review
- **transcode**: Fix an issue where videos with orientation or rotation metadata (such as smartphone vertical videos) were incorrectly displayed with stretched aspect ratios in the video player
- **cli**: Only manage and check PID files in daemon mode, preventing stale PID files, crash-loop conflicts, or spurious process checks during normal foreground and Docker execution
### Changed
- **transcode**: Improve video proxy visual quality and disable B-frames for smoother frame-by-frame seeking and scrubbing
</Update>
<Update label="v0.4.7" description="September 19, 2026">
### Added
- **changelog**: Introduce Keep a Changelog support, historical release summaries, and automated release notes extraction
- **release**: Automatically populate GitHub release bodies from CHANGELOG.md and promote unreleased notes during version bumps
- **settings**: Add FFmpeg threads slider to team media processing settings
- **asset**: Show previews of a folder's contents and a "days left" countdown for each item in Recently Deleted
- **asset**: Show the poster and hover preview for a video in the file list while it is still transcoding, with a gently pulsing cover (or an animated waiting circle before the poster is ready), "Uploading..."/"Preparing..." labels, and the duration hidden until it is ready
### Fixed
- **asset**: Fix an issue where moving a video to trash while it was still transcoding could cause it to lose its trashed status
- **transcode**: Immediately stop background video processing and transcoding when a file is permanently deleted from the trash
- **asset**: Fix proxy download filename using original file extension instead of proxy extension
- **asset**: Fix an issue where deleting or restoring a version stack from the file list did nothing
- **webui**: Center breadcrumb file action popup menu on the chevron icon
</Update>
<Update label="v0.4.6" description="September 17, 2026">
### Added
- **comment**: Add emoji reaction support for comments ([#405](https://github.com/shumaiOne/shumai/pull/405))
- **premiere-uxp**: Introduce Adobe Premiere Pro UXP plugin for Shumai ([#407](https://github.com/shumaiOne/shumai/pull/407))
- **settings**: Add team appearance setting to hide agent features ([#411](https://github.com/shumaiOne/shumai/pull/411))
### Fixed
- **premiere-uxp**: Preserve remote cloud storage presigned URLs in asset resolution ([#408](https://github.com/shumaiOne/shumai/pull/408))
- **premiere-uxp**: Scope sequence links by server endpoint and surface sync errors ([#409](https://github.com/shumaiOne/shumai/pull/409))
- **api**: Enforce SHUMAI_DEMO_MODE for API token and CLI requests ([#413](https://github.com/shumaiOne/shumai/pull/413))
### Documentation
- Add NLE export and Premiere Pro UXP plugin documentation ([#412](https://github.com/shumaiOne/shumai/pull/412))
</Update>
<Update label="v0.4.5" description="September 13, 2026">
### Added
- **core**: Export comments to FCP, Premiere, Media Composer, and Resolve ([#400](https://github.com/shumaiOne/shumai/pull/400))
- **webui**: Add NLE comments export and migrate export API to POST ([#401](https://github.com/shumaiOne/shumai/pull/401))
- **webui**: Add space key quick preview for files and folders ([#402](https://github.com/shumaiOne/shumai/pull/402))
- **webui**: Show comments count badge in file card preview area ([#403](https://github.com/shumaiOne/shumai/pull/403))
- **agent**: Use deterministic storage keys for preset avatars ([#404](https://github.com/shumaiOne/shumai/pull/404))
</Update>
<Update label="v0.4.4" description="September 9, 2026">
### Added
- **upload**: S3 multipart upload with offline resume and wake lock ([#391](https://github.com/shumaiOne/shumai/pull/391))
- **transcode**: Optimize video operations using ffmpeg http range requests ([#393](https://github.com/shumaiOne/shumai/pull/393))
- **agent**: Enable read_asset tool for autofill agent ([#396](https://github.com/shumaiOne/shumai/pull/396))
- **sandbox**: Abstract SandboxService and hot-reload allowed domains ([#398](https://github.com/shumaiOne/shumai/pull/398))
### Fixed
- **s3**: Stream downloadToFile and putObject to prevent OOM on large files ([#392](https://github.com/shumaiOne/shumai/pull/392))
- **agent**: Pass agent thinkingLevel to session name generation ([#395](https://github.com/shumaiOne/shumai/pull/395))
- **agent**: Restrict pageCount and duration recommendations to matching media types ([#397](https://github.com/shumaiOne/shumai/pull/397))
- **transcode**: Co-locate screenshots and derived artifacts in asset storage directory ([#399](https://github.com/shumaiOne/shumai/pull/399))
</Update>
<Update label="v0.4.3" description="September 6, 2026">
### Added
- **asset**: Record and display agent provenance on assets and audit logs ([#380](https://github.com/shumaiOne/shumai/pull/380))
- **agent**: Store preset avatars as real files in s3 storage ([#381](https://github.com/shumaiOne/shumai/pull/381))
- **agent**: Add built-in image and video generation tools and settings ([#382](https://github.com/shumaiOne/shumai/pull/382))
- **media-generation**: Add gemini-omni-1.1-flash video model and redesign settings UI ([#383](https://github.com/shumaiOne/shumai/pull/383))
- **settings**: Redesign image/video settings to provider dialog with model toggles ([#385](https://github.com/shumaiOne/shumai/pull/385))
- **agent**: Add asset management tools and CLI commands ([#387](https://github.com/shumaiOne/shumai/pull/387))
- **cli**: Control asset deletion via SHUMAI_ALLOW_DELETE env var ([#388](https://github.com/shumaiOne/shumai/pull/388))
### Fixed
- **webui**: Clamp file card creation info to 2 lines and show tooltip on hover ([#390](https://github.com/shumaiOne/shumai/pull/390))
### Documentation
- **agents**: Add documentation for image and video generation settings ([#389](https://github.com/shumaiOne/shumai/pull/389))
### Maintenance
- **deps**: Upgrade bun to 1.4.2 and update packages ([#384](https://github.com/shumaiOne/shumai/pull/384))
- **i18n**: Update paraglide-js to 2.25.0 and stop checking in generated code ([#386](https://github.com/shumaiOne/shumai/pull/386))
</Update>
<Update label="v0.4.2" description="September 3, 2026">
### Added
- **chat**: Support markups, attachments, and timestamps in agent 1-to-1 chat ([#368](https://github.com/shumaiOne/shumai/pull/368))
- **agent**: Move thread metadata to structured context XML ([#373](https://github.com/shumaiOne/shumai/pull/373))
- **agent**: Improve timestamp precision and proxy selection for video screenshots ([#374](https://github.com/shumaiOne/shumai/pull/374))
- **agent**: Support dynamic annotationId resolution across chat and comments ([#375](https://github.com/shumaiOne/shumai/pull/375))
- **agent**: Consolidate media tools into read_asset and add S3 key support to download_asset ([#376](https://github.com/shumaiOne/shumai/pull/376))
- **provider**: Optimize provider and model configuration management ([#377](https://github.com/shumaiOne/shumai/pull/377))
- **provider**: Add provider and model sync feature with vendored generator ([#378](https://github.com/shumaiOne/shumai/pull/378))
### Fixed
- **agent**: Set empty details in asset tool results to avoid data duplication ([#370](https://github.com/shumaiOne/shumai/pull/370))
- **webui**: Strip styles and preserve multiline text on paste in chat input ([#371](https://github.com/shumaiOne/shumai/pull/371))
- **agent**: Hide main comment sessions in dashboard sessions list ([#372](https://github.com/shumaiOne/shumai/pull/372))
### Changed
- **webui**: Use semantic system colors in notification settings ([#379](https://github.com/shumaiOne/shumai/pull/379))
</Update>
<Update label="v0.4.1" description="August 30, 2026">
### Added
- **webui**: Add manage versions option to file card context menu ([#364](https://github.com/shumaiOne/shumai/pull/364))
- **agent**: Refactor message context into unified shumai_message ([#365](https://github.com/shumaiOne/shumai/pull/365))
- **webui**: Redesign comment attachment display into compact rows ([#366](https://github.com/shumaiOne/shumai/pull/366))
### Fixed
- **asset,webui**: Disallow dropping version stacks onto files and version stacks ([#363](https://github.com/shumaiOne/shumai/pull/363))
- **webui**: Prevent empty folder flash during initial loading ([#367](https://github.com/shumaiOne/shumai/pull/367))
### Changed
- **agent**: Remove executeAgentToolWorkflow and invoke core services directly ([#362](https://github.com/shumaiOne/shumai/pull/362))
</Update>
<Update label="v0.4.0" description="August 28, 2026">
### Added
- **transcode**: Add hardware-accelerated video transcoding support ([#352](https://github.com/shumaiOne/shumai/pull/352))
- **webui**: Truncate long file names with 100ms hover tooltip ([#355](https://github.com/shumaiOne/shumai/pull/355))
- **webui**: Add simplified mobile-friendly layout for file and share lists ([#356](https://github.com/shumaiOne/shumai/pull/356))
- **webui**: Add mobile friendly file detail and public share view ([#359](https://github.com/shumaiOne/shumai/pull/359))
### Fixed
- **transcode**: Apply team hardware acceleration and source bitrate capping to watermark transcoding ([#353](https://github.com/shumaiOne/shumai/pull/353))
- **share**: Hide and soft-delete symlinks when target assets are trashed ([#354](https://github.com/shumaiOne/shumai/pull/354))
- **webui**: Fix breadcrumb file dropdown trigger stretching and alignment ([#360](https://github.com/shumaiOne/shumai/pull/360))
- **webui**: Align mobile comment cards and thread vertical indicator ([#361](https://github.com/shumaiOne/shumai/pull/361))
### Documentation
- Add SECURITY.md with a private disclosure path ([#357](https://github.com/shumaiOne/shumai/pull/357))
</Update>
<Update label="v0.3.11" description="August 25, 2026">
### Added
- **auth**: Add admin password reset CLI command and reset password web UI ([#347](https://github.com/shumaiOne/shumai/pull/347))
- **project**: Add recent viewed files section to project folder tree ([#348](https://github.com/shumaiOne/shumai/pull/348))
### Fixed
- **webui**: Prevent left carousel remounting and scroll jump on file selection ([#351](https://github.com/shumaiOne/shumai/pull/351))
</Update>
<Update label="v0.3.10" description="August 23, 2026">
### Added
- **agentic kanban**: Phase 1 not-agentic kanban board ([#330](https://github.com/shumaiOne/shumai/pull/330))
- **kanban**: Resolve latest version for linked version stack assets and update demo login text ([#342](https://github.com/shumaiOne/shumai/pull/342))
- **kanban**: Update task status permissions, reporter defaults, and participant access ([#345](https://github.com/shumaiOne/shumai/pull/345))
### Fixed
- **kanban**: Use true thumbnail and poster for task asset previews ([#343](https://github.com/shumaiOne/shumai/pull/343))
- **webui**: Sidebar selection styling, kanban active state, pointer cursors, and owner dashboard ([#344](https://github.com/shumaiOne/shumai/pull/344))
- **kanban**: Improve drag-drop to column bottom, remove empty drop line, and fix timeline alignment ([#346](https://github.com/shumaiOne/shumai/pull/346))
</Update>
<Update label="v0.3.9" description="August 18, 2026">
### Added
- **agent**: Add permission controls for chat agents ([#313](https://github.com/shumaiOne/shumai/pull/313))
- **authz**: Enforce project-aware roles for agent/skill/mcp permissions ([#314](https://github.com/shumaiOne/shumai/pull/314))
- **webui**: Use project members for asset comment mentions ([#315](https://github.com/shumaiOne/shumai/pull/315))
- **quota**: Add 2-level database-backed resource quota system ([#318](https://github.com/shumaiOne/shumai/pull/318))
- **settings**: Reorganize settings into personal, team, and AI sections ([#324](https://github.com/shumaiOne/shumai/pull/324))
- **quota**: Move usage monitoring to team dashboard ([#327](https://github.com/shumaiOne/shumai/pull/327))
### Fixed
- **webui**: Preserve selected chatbot agent preference on reload ([#323](https://github.com/shumaiOne/shumai/pull/323))
- **quota**: Exclude agents from quota rules and usage records ([#325](https://github.com/shumaiOne/shumai/pull/325))
### Documentation
- **team-settings**: Add resource quotas documentation and update readme features ([#326](https://github.com/shumaiOne/shumai/pull/326))
</Update>
<Update label="v0.3.8" description="August 15, 2026">
### Added
- **webui**: Replace legacy markdown editor with new lexical wysiwyg editor ([#308](https://github.com/shumaiOne/shumai/pull/308))
- **agent**: Add nested agents.md support across backend and webui ([#309](https://github.com/shumaiOne/shumai/pull/309))
- **webui**: Improve AGENTS.md editor placeholder and read-only notice ([#310](https://github.com/shumaiOne/shumai/pull/310))
- **version-stack**: Add manage versions dialog and version removal ([#311](https://github.com/shumaiOne/shumai/pull/311))
### Fixed
- **core**: Rename latest version child record on version stack rename ([#312](https://github.com/shumaiOne/shumai/pull/312))
</Update>
<Update label="v0.3.7" description="August 14, 2026">
### Added
- **metadata**: Replace aiAutofill boolean with autofillSource enum ([#302](https://github.com/shumaiOne/shumai/pull/302))
- **agent**: Type-safe CREATION_CONTEXT metadata on create_file/create_version ([#303](https://github.com/shumaiOne/shumai/pull/303))
- **sandbox**: Default Network Sandbox to off and add settings toggle switch ([#304](https://github.com/shumaiOne/shumai/pull/304))
- **webui**: Redesign select metadata fields and improve long text field widget ([#305](https://github.com/shumaiOne/shumai/pull/305))
- **agent**: Support dynamic newOption in select and selectMulti metadata fields ([#306](https://github.com/shumaiOne/shumai/pull/306))
### Fixed
- **webui**: Fix select field height and multi-select overflow/interaction issues ([#307](https://github.com/shumaiOne/shumai/pull/307))
</Update>
<Update label="v0.3.6" description="August 12, 2026">
### Added
- **mcp**: Add MCP server support with proxy tool and OAuth flow ([#289](https://github.com/shumaiOne/shumai/pull/289))
- **mcp**: Support tool-level directTools array and 3-state UI configuration ([#297](https://github.com/shumaiOne/shumai/pull/297))
- **webui**: Direct canvas PDF rendering with selectable text ([#299](https://github.com/shumaiOne/shumai/pull/299))
### Fixed
- **agent**: Prevent agents from accessing disabled skills ([#292](https://github.com/shumaiOne/shumai/pull/292))
- **agent**: Resolve version stack name and size in list_assets ([#296](https://github.com/shumaiOne/shumai/pull/296))
- **webui**: Content-only pinch-zoom and two-finger pan in media viewers ([#298](https://github.com/shumaiOne/shumai/pull/298))
- **i18n**: Update Chinese translation for dashboard to 仪表板 ([#301](https://github.com/shumaiOne/shumai/pull/301))
### Documentation
- **mcp**: Add MCP support documentation to README and docs ([#300](https://github.com/shumaiOne/shumai/pull/300))
</Update>
<Update label="v0.3.5" description="August 9, 2026">
### Added
- **transcode**: Add Gotenberg support for Office, HTML, CSV, and Markdown PDF proxies ([#283](https://github.com/shumaiOne/shumai/pull/283))
### Fixed
- **webui**: Resolve upload card freeze for unsupported files ([#284](https://github.com/shumaiOne/shumai/pull/284))
- **webui**: Exclude file extension when selecting file name during inline rename ([#285](https://github.com/shumaiOne/shumai/pull/285))
- Use renamed asset name in download Content-Disposition ([#286](https://github.com/shumaiOne/shumai/pull/286))
- **webui**: Batch download no longer flashes a tab per file ([#287](https://github.com/shumaiOne/shumai/pull/287))
- **webui**: Enable rename and delete actions in file detail top bar breadcrumb ([#288](https://github.com/shumaiOne/shumai/pull/288))
</Update>
<Update label="v0.3.4" description="August 8, 2026">
### Added
- **sharelink**: Add sharelink watermark support ([#270](https://github.com/shumaiOne/shumai/pull/270))
- **webui**: Remove original-file display fallbacks, use proxies only ([#273](https://github.com/shumaiOne/shumai/pull/273))
- **share**: Add allow download config to share links ([#275](https://github.com/shumaiOne/shumai/pull/275))
- **transcode**: Update preview thumbnail resolution to 300p with max length constraint ([#281](https://github.com/shumaiOne/shumai/pull/281))
### Fixed
- **share**: Resolve symlink asset downloads in public share pages ([#274](https://github.com/shumaiOne/shumai/pull/274))
- **webui**: Persist project sorting and prevent full page flash ([#276](https://github.com/shumaiOne/shumai/pull/276))
### Documentation
- **share-links**: Document allow download and lazy watermark settings ([#278](https://github.com/shumaiOne/shumai/pull/278))
- **agent**: Clarify create_file/create_version context param guidance ([#282](https://github.com/shumaiOne/shumai/pull/282))
### Maintenance
- **e2e**: Watermarked download-disabled share link coverage (image + video) ([#277](https://github.com/shumaiOne/shumai/pull/277))
- **e2e**: Stabilize watermark share spec on Firefox ([#279](https://github.com/shumaiOne/shumai/pull/279))
- Split e2e scripts into app and webui targets ([#280](https://github.com/shumaiOne/shumai/pull/280))
</Update>
<Update label="v0.3.3" description="August 5, 2026">
### Added
- **agent**: Enable LLM API call retries in AgentHarness ([#250](https://github.com/shumaiOne/shumai/pull/250))
- **audit**: Add audit log support for APIs and WebUI dashboard ([#251](https://github.com/shumaiOne/shumai/pull/251))
- **webui**: Persist agent preference in localStorage ([#254](https://github.com/shumaiOne/shumai/pull/254))
- **e2e**: Add file domain comment and draw tests ([#260](https://github.com/shumaiOne/shumai/pull/260))
- **agent**: Restrict bash access for non-owner users ([#262](https://github.com/shumaiOne/shumai/pull/262))
- **agent**: Allow create_file tool to create files directly from content ([#263](https://github.com/shumaiOne/shumai/pull/263))
- **agent**: Propagate autofill context from chat to autofill workflow ([#264](https://github.com/shumaiOne/shumai/pull/264))
- **webui**: Render select options in field creation mode and pick random option color ([#265](https://github.com/shumaiOne/shumai/pull/265))
- **project**: Include team-scoped members in project member list and add 3-section dialog layout ([#267](https://github.com/shumaiOne/shumai/pull/267))
- **webui**: Disable role dropdown for project-scoped members in team view ([#269](https://github.com/shumaiOne/shumai/pull/269))
### Fixed
- **webui**: Mention popup avatars, keyboard auto-scroll, and non-sticky section headers ([#256](https://github.com/shumaiOne/shumai/pull/256))
- **webui**: Persist field order on drag and drop ([#266](https://github.com/shumaiOne/shumai/pull/266))
### Changed
- **agent**: Load models directly from database without pi fallback ([#253](https://github.com/shumaiOne/shumai/pull/253))
- **core**: Replace generated provider files with pi-ai dynamic methods ([#255](https://github.com/shumaiOne/shumai/pull/255))
### Maintenance
- **core**: Add missing tests for methods introduced in 97069042 ([#252](https://github.com/shumaiOne/shumai/pull/252))
- **e2e**: Add domain-based auth and project web app e2e tests ([#257](https://github.com/shumaiOne/shumai/pull/257))
- **e2e**: Add file, share, and collection web app e2e tests ([#258](https://github.com/shumaiOne/shumai/pull/258))
- **e2e**: Add project-level invite and file-move e2e tests ([#259](https://github.com/shumaiOne/shumai/pull/259))
- **e2e**: Add search in file list and save-search-as-collection cases ([#261](https://github.com/shumaiOne/shumai/pull/261))
- **e2e**: Add member permission change tests ([#268](https://github.com/shumaiOne/shumai/pull/268))
</Update>
<Update label="v0.3.2" description="July 30, 2026">
### Added
- **agent**: Add output truncation and streaming limits to sandboxed bash tool ([#248](https://github.com/shumaiOne/shumai/pull/248))
### Fixed
- **agent**: Download original document asset instead of pdf proxy ([#247](https://github.com/shumaiOne/shumai/pull/247))
- **webui**: Persist chatbot sidebar input text across route navigation ([#249](https://github.com/shumaiOne/shumai/pull/249))
</Update>
<Update label="v0.3.1" description="July 30, 2026">
### Added
- **transcode**: Trigger ai metadata autofill post transcode ([#234](https://github.com/shumaiOne/shumai/pull/234))
- **dashboard**: Add agent sessions view for team owners ([#237](https://github.com/shumaiOne/shumai/pull/237))
- **db**: Preserve agent sessions on asset deletion by setting onDelete to SetNull ([#240](https://github.com/shumaiOne/shumai/pull/240))
- **agent**: Add download_asset tool and prompt instructions ([#242](https://github.com/shumaiOne/shumai/pull/242))
- **db**: Update Asset.sizeByte and AiUsage token fields to BigInt ([#244](https://github.com/shumaiOne/shumai/pull/244))
### Fixed
- **agent**: Include select option labels and field name in autofill schema ([#235](https://github.com/shumaiOne/shumai/pull/235))
- **agent**: Scope agent comment sessions to thread sessions anchored at root comments ([#239](https://github.com/shumaiOne/shumai/pull/239))
- **agent**: Disable tools for session naming and make naming non-blocking ([#241](https://github.com/shumaiOne/shumai/pull/241))
- **webui**: Update file size formatting to SI decimal standard ([#245](https://github.com/shumaiOne/shumai/pull/245))
- **s3**: Enforce property syntax in S3Service interface and fix ReadableStream handling in S3StorageService ([#246](https://github.com/shumaiOne/shumai/pull/246))
</Update>
<Update label="v0.3.0" description="July 28, 2026">
### Added
- **file-browser**: Add copy name and path option to context menu ([#225](https://github.com/shumaiOne/shumai/pull/225))
- **agent**: Inject user name and role into chat context ([#226](https://github.com/shumaiOne/shumai/pull/226))
- **agent**: Refactor database session storage to normalized DAG entries and lazy thread sync ([#229](https://github.com/shumaiOne/shumai/pull/229))
- **agent**: Support ENABLE_WEAKER_NESTED_SANDBOX environment variable ([#233](https://github.com/shumaiOne/shumai/pull/233))
### Fixed
- **agent**: Ensure atomic appendEntry and persist leaf entries in DatabaseSessionStorage ([#224](https://github.com/shumaiOne/shumai/pull/224))
- Sharp version mismatch bug ([#230](https://github.com/shumaiOne/shumai/pull/230))
- **agent**: Resolve S3 MIME type detection and prompt parameter in image analysis ([#232](https://github.com/shumaiOne/shumai/pull/232))
### Changed
- **agent**: Remove implicit agent mention trigger in comment threads ([#227](https://github.com/shumaiOne/shumai/pull/227))
### Maintenance
- **workflow**: Add docker compose deployment verification job ([#231](https://github.com/shumaiOne/shumai/pull/231))
</Update>
<Update label="v0.2.3" description="July 25, 2026">
### Fixed
- **webui**: Show right sidebar by default on file detail page ([#219](https://github.com/shumaiOne/shumai/pull/219))
- **webui**: Refresh file list and detail when agent executes asset creation tools ([#220](https://github.com/shumaiOne/shumai/pull/220))
- **webui**: Fix space key drag overlay and shift range selection for version stacks ([#221](https://github.com/shumaiOne/shumai/pull/221))
- **transcode**: Handle timestamp rounding tolerance for screenshot annotations ([#223](https://github.com/shumaiOne/shumai/pull/223))
### Changed
- **e2e**: Split transcode workflow E2E tests into per-workflow test files ([#222](https://github.com/shumaiOne/shumai/pull/222))
</Update>
<Update label="v0.2.2" description="July 23, 2026">
### Added
- **webui**: Integrate AI usage API into dashboard page ([#216](https://github.com/shumaiOne/shumai/pull/216))
- **ai-usage**: Add team and member token usage tracking and APIs ([#215](https://github.com/shumaiOne/shumai/pull/215))
- **transcode**: Add PSD support via ImageMagick and enforce sRGB conversion ([#217](https://github.com/shumaiOne/shumai/pull/217))
### Fixed
- **search**: Fix buildSqlCondition date range, numeric metadata, and string parsing bugs ([#213](https://github.com/shumaiOne/shumai/pull/213))
- **webui**: Prevent horizontal overflow in search dialog result rows ([#214](https://github.com/shumaiOne/shumai/pull/214))
- **webui**: Invalidate upload tasks query when upload task starts and completes ([#218](https://github.com/shumaiOne/shumai/pull/218))
</Update>
<Update label="v0.2.1" description="July 22, 2026">
### Added
- **skill**: Add team owner skill permission control ([#209](https://github.com/shumaiOne/shumai/pull/209))
### Fixed
- **agent**: Handle non-builtin models in getModelFromDb and upgrade pi-ai ([#211](https://github.com/shumaiOne/shumai/pull/211))
- **provider**: Preserve model ids on provider update ([#212](https://github.com/shumaiOne/shumai/pull/212))
### Changed
- **core**: Split generated providers into per-provider files ([#210](https://github.com/shumaiOne/shumai/pull/210))
</Update>
<Update label="v0.2.0" description="July 21, 2026">
### Added
- **transcode**: Add PDF preview, sprite generation, and annotation support ([#193](https://github.com/shumaiOne/shumai/pull/193))
- **web**: Register pdf.worker route in production ([#195](https://github.com/shumaiOne/shumai/pull/195))
- **agent**: Add read_pdf_pages tool and PDF page context support ([#196](https://github.com/shumaiOne/shumai/pull/196))
- **transcode**: Split monolithic transcodeMedia into focused workflows ([#197](https://github.com/shumaiOne/shumai/pull/197))
- **transcode**: Add PDF proxy support for TXT and CSV files ([#199](https://github.com/shumaiOne/shumai/pull/199))
- **asset**: Replace mediaType/mimeType logic with proxyType ([#200](https://github.com/shumaiOne/shumai/pull/200))
- **docker**: Install fonts-noto-cjk in runner stage ([#202](https://github.com/shumaiOne/shumai/pull/202))
- **transcode**: Add markdown file to pdf proxy support ([#203](https://github.com/shumaiOne/shumai/pull/203))
- **chat**: Track context asset changes and update agent context ([#204](https://github.com/shumaiOne/shumai/pull/204))
- **agent**: Refactor media tools to static injection with mandatory assetId and authz ([#208](https://github.com/shumaiOne/shumai/pull/208))
### Fixed
- **transcode**: Mark pdfkit as external and extract for docker runtime ([#201](https://github.com/shumaiOne/shumai/pull/201))
- **agent**: Include skill id in formatSkillsForPrompt ([#205](https://github.com/shumaiOne/shumai/pull/205))
- **asset**: Exclude soft-deleted children from latestChildren preview ([#206](https://github.com/shumaiOne/shumai/pull/206))
- **agent**: Pass latest version asset from version stack to prompt builder ([#207](https://github.com/shumaiOne/shumai/pull/207))
</Update>
<Update label="v0.1.10" description="July 16, 2026">
### Added
- **workflow-e2e**: Add E2E tests for agentAutofillMedia workflow ([#188](https://github.com/shumaiOne/shumai/pull/188))
- **comments**: Support comment deletion and video player shortcuts ([#191](https://github.com/shumaiOne/shumai/pull/191))
- **agent**: Support disabling specific tools for agents ([#192](https://github.com/shumaiOne/shumai/pull/192))
### Maintenance
- **e2e**: Add E2E workflow tests for remaining agent and transcode services ([#189](https://github.com/shumaiOne/shumai/pull/189))
</Update>
<Update label="v0.1.9" description="July 14, 2026">
### Added
- **e2e**: Set up fullstack app-level e2e test framework and signup test case ([#184](https://github.com/shumaiOne/shumai/pull/184))
- **chat**: Chatbot UI ([#185](https://github.com/shumaiOne/shumai/pull/185))
- **agent**: Support aborting agent execution ([#186](https://github.com/shumaiOne/shumai/pull/186))
### Changed
- **api/chat**: Remove direct Prisma query from API layer ([#187](https://github.com/shumaiOne/shumai/pull/187))
</Update>
<Update label="v0.1.8" description="July 10, 2026">
### Added
- **chatbot**: Implement type-safe Chat APIs with compaction support ([#180](https://github.com/shumaiOne/shumai/pull/180))
### Fixed
- **webui**: Enable build splitting and code-split all page routes ([#183](https://github.com/shumaiOne/shumai/pull/183))
### Documentation
- **readme**: Clarify displayed file size represents original file size ([#182](https://github.com/shumaiOne/shumai/pull/182))
</Update>
<Update label="v0.1.7" description="July 6, 2026">
### Added
- **audio**: Support frame-accurate audio playback, comments, and AI safeguards ([#175](https://github.com/shumaiOne/shumai/pull/175))
- **i18n**: Localize members dialog, notifications, uploads, user menus, dates, and players ([#178](https://github.com/shumaiOne/shumai/pull/178))
- **comments**: Allow marking comments as complete or incomplete ([#179](https://github.com/shumaiOne/shumai/pull/179))
### Fixed
- **upload**: Resolve empty and generic MIME types in confirmFileUpload ([#176](https://github.com/shumaiOne/shumai/pull/176))
### Changed
- **webui**: Modularize file viewer components into registry-driven architecture ([#174](https://github.com/shumaiOne/shumai/pull/174))
### Documentation
- Improve documentation and examples for S3 compatible storage ([#177](https://github.com/shumaiOne/shumai/pull/177))
</Update>
<Update label="v0.1.6" description="July 4, 2026">
### Added
- **file-browser**: Show video duration on file card preview ([#170](https://github.com/shumaiOne/shumai/pull/170))
- **webui**: Compare versions view for version stacks ([#171](https://github.com/shumaiOne/shumai/pull/171))
### Fixed
- **webui**: Resolve conditional hooks and setState-in-render errors ([#167](https://github.com/shumaiOne/shumai/pull/167))
- **webui**: Resolve video player total frames mismatch ([#172](https://github.com/shumaiOne/shumai/pull/172))
- **version-stack**: Resolve correct latest version ID of version stack ([#173](https://github.com/shumaiOne/shumai/pull/173))
### Maintenance
- **webui**: Video player e2e framework + Safari playhead fix ([#166](https://github.com/shumaiOne/shumai/pull/166))
- **webui**: Add frame-accurate comment seek roundtrip e2e ([#168](https://github.com/shumaiOne/shumai/pull/168))
- **webui**: Verify video player restarts playback after end ([#169](https://github.com/shumaiOne/shumai/pull/169))
</Update>
<Update label="v0.1.5" description="July 2, 2026">
### Changed
- **storage**: Use original filenames for stored files ([#165](https://github.com/shumaiOne/shumai/pull/165))
### Maintenance
- **release**: Add Aliyun ACR push to release workflow ([#164](https://github.com/shumaiOne/shumai/pull/164))
</Update>
<Update label="v0.1.4" description="July 1, 2026">
### Added
- **transcode**: Change video poster resolution to 480p ([#161](https://github.com/shumaiOne/shumai/pull/161))
- **auth**: Allow setting user locale on signup ([#163](https://github.com/shumaiOne/shumai/pull/163))
### Fixed
- **webui**: Preserve video ended state by skipping playhead snap on ended ([#162](https://github.com/shumaiOne/shumai/pull/162))
</Update>
<Update label="v0.1.3" description="June 30, 2026">
### Added
- **webui**: Add i18n support using paraglide-js ([#156](https://github.com/shumaiOne/shumai/pull/156))
- **video**: Add frame-accurate video player, SMPTE timecodes, and format switcher ([#157](https://github.com/shumaiOne/shumai/pull/157))
### Fixed
- **webui**: Align video timeline duration and formatting with frameio ([#158](https://github.com/shumaiOne/shumai/pull/158))
- **webui**: Fix missing left sidebar for nested folders ([#159](https://github.com/shumaiOne/shumai/pull/159))
- **api**: Fix update team settings and make request schema type-safe ([#160](https://github.com/shumaiOne/shumai/pull/160))
</Update>
<Update label="v0.1.2" description="June 25, 2026">
### Changed
- **s3**: Remove automatic port appending to AWS_ENDPOINT_URL_S3 ([#155](https://github.com/shumaiOne/shumai/pull/155))
</Update>
<Update label="v0.1.1" description="June 23, 2026">
### Added
- **docker**: Add root entrypoint with privilege dropping for data volumes ([#151](https://github.com/shumaiOne/shumai/pull/151))
</Update>
<Update label="v0.1.0" description="June 22, 2026">
### Added
- **share**: Secure share info API and fix wrong password feedback ([#150](https://github.com/shumaiOne/shumai/pull/150))
### Fixed
- **webui**: Truncate long folder, collection, and share link names in sidebar ([#149](https://github.com/shumaiOne/shumai/pull/149))
</Update>
<Update label="v0.0.11" description="June 22, 2026">
### Added
- **cli**: Add shumai-cli and token authentication ([#144](https://github.com/shumaiOne/shumai/pull/144))
- **settings**: Use singular headers and remove collapse/counters for single agent types ([#145](https://github.com/shumaiOne/shumai/pull/145))
- **folders**: Auto expand folder tree in left sidebar on navigation ([#146](https://github.com/shumaiOne/shumai/pull/146))
- **metadata**: Add single user and multiple user custom fields ([#147](https://github.com/shumaiOne/shumai/pull/147))
### Maintenance
- **cli**: Rename npm package to @shumai-one/shumai-cli ([#148](https://github.com/shumaiOne/shumai/pull/148))
</Update>
<Update label="v0.0.10" description="June 21, 2026">
### Changed
- **web**: Dynamically register production HTML bundle routes ([#142](https://github.com/shumaiOne/shumai/pull/142))
### Documentation
- **readme**: Polish structure, correct grammar, and add dependencies table ([#143](https://github.com/shumaiOne/shumai/pull/143))
</Update>
<Update label="v0.0.9" description="June 20, 2026">
### Added
- **webui**: Show app version in avatar menu ([#139](https://github.com/shumaiOne/shumai/pull/139))
- **cli**: Add background daemonization and subcommands ([#141](https://github.com/shumaiOne/shumai/pull/141))
### Maintenance
- **release**: Add smoke tests to local release stage ([#140](https://github.com/shumaiOne/shumai/pull/140))
</Update>
<Update label="v0.0.8" description="June 19, 2026">
### Added
- **api**: Implement read-only mode for reviewers ([#122](https://github.com/shumaiOne/shumai/pull/122))
- **server**: Allow customizing server port via SHUMAI_SERVER_PORT ([#124](https://github.com/shumaiOne/shumai/pull/124))
- **embedding**: Defer embedding workflow, use transcoded assets, and execute chunks in separate activities ([#125](https://github.com/shumaiOne/shumai/pull/125))
- **webui**: Add external drag-and-drop file and folder upload support ([#126](https://github.com/shumaiOne/shumai/pull/126))
- **agent**: Implement overlapping video chunks for semantic search ([#127](https://github.com/shumaiOne/shumai/pull/127))
- **webui**: Support jumping to video timestamp from search results ([#128](https://github.com/shumaiOne/shumai/pull/128))
- **auth**: Add demo mode support ([#131](https://github.com/shumaiOne/shumai/pull/131))
- **auth**: Refine demo mode support ([#132](https://github.com/shumaiOne/shumai/pull/132))
- **webui**: Default right sidebar to collapsed for new users ([#133](https://github.com/shumaiOne/shumai/pull/133))
- **webui**: Use Shadcn Switch in toggle field and Rating component in search filter panel ([#137](https://github.com/shumaiOne/shumai/pull/137))
- **upload**: Track byte-level progress with XMLHttpRequest ([#138](https://github.com/shumaiOne/shumai/pull/138))
### Fixed
- **transcode**: Handle high-precision FPS using rational fractions ([#123](https://github.com/shumaiOne/shumai/pull/123))
- **db**: Automatically update project updatedAt on asset modification ([#129](https://github.com/shumaiOne/shumai/pull/129))
- **webui**: Use system colors for fields and improve search filter select options ([#130](https://github.com/shumaiOne/shumai/pull/130))
- **search**: Fix hasAny and hasNone operators on metadata filter ([#134](https://github.com/shumaiOne/shumai/pull/134))
- **webui**: Resolve folder tree sync, search dialog reset, and sidebar actions issues ([#136](https://github.com/shumaiOne/shumai/pull/136))
### Changed
- **webui**: Fix search dialog layout height, scroll areas, and restrict filter toggle click ([#135](https://github.com/shumaiOne/shumai/pull/135))
</Update>
<Update label="v0.0.7" description="June 17, 2026">
### Added
- **workflow**: Configure transcode and agent concurrency via environment variables ([#116](https://github.com/shumaiOne/shumai/pull/116))
- **webui**: Replace hardcoded colors with system tokens ([#119](https://github.com/shumaiOne/shumai/pull/119))
- **webui**: Replace native overflow with shadcn ScrollArea in settings ([#120](https://github.com/shumaiOne/shumai/pull/120))
- **api**: Use enum for API protocol in provider config ([#121](https://github.com/shumaiOne/shumai/pull/121))
### Fixed
- **webui**: Reload video player and reset state when switching assets ([#114](https://github.com/shumaiOne/shumai/pull/114))
### Changed
- **transcode**: Relocate TranscodeService to core and flatten API package ([#115](https://github.com/shumaiOne/shumai/pull/115))
### Documentation
- Improve and restructure shumai documentation ([#118](https://github.com/shumaiOne/shumai/pull/118))
</Update>
<Update label="v0.0.6" description="June 15, 2026">
### Added
- **sandbox**: Add pending domains support for network sandbox ([#109](https://github.com/shumaiOne/shumai/pull/109))
- **webui**: Always show right sidebar and implement left vertical carousel ([#111](https://github.com/shumaiOne/shumai/pull/111))
### Fixed
- **build**: Propagate termination signals to active child process in wrappers ([#102](https://github.com/shumaiOne/shumai/pull/102))
- **transcode**: Make deterministic transcode activity failures non-retryable in Temporal ([#104](https://github.com/shumaiOne/shumai/pull/104))
- **player**: Implement seekbar dragging and match hover highlight color ([#108](https://github.com/shumaiOne/shumai/pull/108))
- **webui**: Avoid refetching all pages on file/folder reorder ([#112](https://github.com/shumaiOne/shumai/pull/112))
- **webui**: Force video-player mime type to video/mp4 ([#113](https://github.com/shumaiOne/shumai/pull/113))
### Changed
- **webui**: Use system color design tokens in video player components ([#106](https://github.com/shumaiOne/shumai/pull/106))
- **webui**: Use requestAnimationFrame for smooth video progress bar updates ([#107](https://github.com/shumaiOne/shumai/pull/107))
- **webui**: Fetch agents in mention input list dynamically ([#110](https://github.com/shumaiOne/shumai/pull/110))
### Documentation
- **readme**: Add comprehensive README.md ([#103](https://github.com/shumaiOne/shumai/pull/103))
- **readme**: Improve remote deployment and temporal execution instructions ([#105](https://github.com/shumaiOne/shumai/pull/105))
</Update>
<Update label="v0.0.5" description="June 13, 2026">
### Added
- **npm**: Auto deploy database migrations on package start ([#101](https://github.com/shumaiOne/shumai/pull/101))
</Update>
<Update label="v0.0.4" description="June 12, 2026">
### Fixed
- **cli/docker**: Resolve global CLI external dependencies and fix Docker 404 error ([#100](https://github.com/shumaiOne/shumai/pull/100))
</Update>
<Update label="v0.0.3" description="June 12, 2026">
### Fixed
- **cli**: Resolve platform binary path resolution under nested node_modules ([#99](https://github.com/shumaiOne/shumai/pull/99))
</Update>
<Update label="v0.0.2" description="June 12, 2026">
### Fixed
- **npm**: Add repository metadata to package.json for provenance verification ([#98](https://github.com/shumaiOne/shumai/pull/98))
### Maintenance
- Add release-npm.yaml workflow ([#97](https://github.com/shumaiOne/shumai/pull/97))
</Update>
<Update label="v0.0.1" description="June 12, 2026">
### Added
- Initial release of Shumai
</Update>
+12
View File
@@ -12,6 +12,14 @@
"light": "#F5B895",
"dark": "#A8384D"
},
"navbar": {
"links": [
{
"label": "Changelog",
"href": "/changelog"
}
]
},
"navigation": {
"groups": [
{
@@ -67,6 +75,10 @@
{
"group": "Temporal Deployment",
"pages": ["configuration/temporal"]
},
{
"group": "Releases",
"pages": ["changelog"]
}
]
}
+4 -2
View File
@@ -1,6 +1,6 @@
{
"name": "shumai",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"repository": {
@@ -39,7 +39,9 @@
"release:patch": "bun run scripts/release.ts patch",
"release:minor": "bun run scripts/release.ts minor",
"release:major": "bun run scripts/release.ts major",
"changelog:extract": "bun run scripts/extract-changelog.ts"
"changelog:extract": "bun run scripts/extract-changelog.ts",
"docs:changelog": "bun run scripts/generate-docs-changelog.ts",
"docs:changelog:check": "bun run scripts/generate-docs-changelog.ts --check"
},
"devDependencies": {
"@eslint/js": "10.0.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/agent",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/api",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1
View File
@@ -55,6 +55,7 @@ async function applyWatermarkToAssetMedia(
width: vt.width ?? 0,
height: vt.height ?? 0,
size: 0,
hdr: vt.hdr,
})),
)
: []
+45
View File
@@ -418,6 +418,51 @@ describe('Share API', () => {
expect(body.media.imageTranscodes).toEqual([])
})
test('serves watermarked transcodes with hdr flags preserved when watermark enabled and completed', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(
new Map([
[
'file1',
watermarkMediaInfo({
videoTranscodes: [
{ key: 'files/watermarked-1080p.mp4', width: 1920, height: 1080, hdr: false },
{ key: 'files/watermarked-1080p-hdr.mp4', width: 1920, height: 1080, hdr: true },
],
}),
],
]),
)
const res = await app.request('/shares/share1/files/file1', {
method: 'GET',
headers: { 'x-share-password': 'pass' },
})
expect(res.status).toBe(200)
const body = await res.json()
expect(body.media.videoTranscodes).toEqual([
{
id: 'files/watermarked-1080p.mp4',
url: 'http://s3/presigned',
key: 'files/watermarked-1080p.mp4',
width: 1920,
height: 1080,
size: 0,
hdr: false,
},
{
id: 'files/watermarked-1080p-hdr.mp4',
url: 'http://s3/presigned',
key: 'files/watermarked-1080p-hdr.mp4',
width: 1920,
height: 1080,
size: 0,
hdr: true,
},
])
})
test('serves empty transcode arrays while watermark transcoding is in flight', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(new Map())
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/core",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+19 -2
View File
@@ -365,7 +365,15 @@ describe('TeamService', () => {
})
const settings = await teamService.getSettings(team.id)
expect(settings).toEqual({ semanticSearchEnabled: false, appearance: { hideAgent: false } })
expect(settings).toEqual({
semanticSearchEnabled: false,
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'off',
threads: 0,
},
appearance: { hideAgent: false },
})
await teamService.updateSettings(team.id, 'theme', 'dark')
@@ -373,6 +381,11 @@ describe('TeamService', () => {
expect(newSettings).toEqual({
theme: 'dark',
semanticSearchEnabled: false,
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'off',
threads: 0,
},
appearance: { hideAgent: false },
})
@@ -384,7 +397,11 @@ describe('TeamService', () => {
const finalSettings = await teamService.getSettings(team.id)
expect(finalSettings).toEqual({
theme: 'dark',
transcode: { videoStrategy: 'all', hardwareAcceleration: 'auto', threads: 4 },
transcode: {
videoStrategy: 'all',
hardwareAcceleration: 'auto',
threads: 4,
},
appearance: { hideAgent: true },
semanticSearchEnabled: false,
})
+13 -1
View File
@@ -33,7 +33,11 @@ export class TeamService {
data: {
name: 'Default Team',
settings: {
transcode: { videoStrategy: 'best_match', hardwareAcceleration: 'off', threads: 0 },
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'off',
threads: 0,
},
},
sandbox: { create: {} },
},
@@ -301,6 +305,14 @@ export class TeamService {
})
settings.semanticSearchEnabled = !!embeddingAgent
if (!settings.transcode) {
settings.transcode = {
videoStrategy: 'best_match',
hardwareAcceleration: 'off',
threads: 0,
}
}
if (!settings.appearance) {
settings.appearance = { hideAgent: false }
} else if (settings.appearance.hideAgent === undefined) {
+488 -11
View File
@@ -7,6 +7,7 @@ import {
getDefaultBitrateBps,
calculateMaxBitrate,
H264_ENCODER_CONFIGS,
buildSdrToneMapFilterChain,
} from './transcode'
import { s3Service } from '@shumai/core/src/s3/s3'
import * as path from 'path'
@@ -1311,7 +1312,7 @@ describe('TranscodeService', () => {
const encoder = await transcodeService.selectH264Encoder('auto', 'darwin')
expect(encoder.name).toBe('h264_videotoolbox')
expect(encoder.presetArgs).toEqual(['-q:v', '74'])
expect(encoder.presetArgs).toEqual([])
})
it('selectH264Encoder should select h264_nvenc on linux when available', async () => {
@@ -1447,10 +1448,10 @@ describe('TranscodeService', () => {
const encoder = await transcodeService.selectH264Encoder('auto', 'linux')
expect(encoder.name).toBe('libx264')
expect(encoder.presetArgs).toEqual(['-preset', 'fast', '-crf', '26'])
expect(encoder.presetArgs).toEqual(['-preset', 'fast', '-crf', '23', '-bf', '0'])
})
it('transcodeVideo with hardwareAcceleration off should use libx264, preset fast, crf 26, maxrate, and yuv420p', async () => {
it('transcodeVideo with hardwareAcceleration off should use libx264, preset fast, crf 23, -bf 0, maxrate, and yuv420p', async () => {
vi.mocked(execFile).mockImplementation(
(
_cmd: unknown,
@@ -1486,7 +1487,9 @@ describe('TranscodeService', () => {
'-preset',
'fast',
'-crf',
'26',
'23',
'-bf',
'0',
'-maxrate',
'720k',
'-bufsize',
@@ -1498,7 +1501,7 @@ describe('TranscodeService', () => {
)
})
it('transcodeVideo with hardwareAcceleration auto and videotoolbox should use -q:v 74 and -maxrate', async () => {
it('transcodeVideo with hardwareAcceleration auto and videotoolbox should use -b:v and no maxrate', async () => {
vi.spyOn(transcodeService, 'selectH264Encoder').mockResolvedValue(
H264_ENCODER_CONFIGS.h264_videotoolbox,
)
@@ -1535,17 +1538,16 @@ describe('TranscodeService', () => {
expect.arrayContaining([
'-c:v',
'h264_videotoolbox',
'-q:v',
'74',
'-maxrate',
'-b:v',
'720k',
'-bufsize',
'1440k',
'-pix_fmt',
'yuv420p',
]),
expect.any(Function),
)
const callArgs = vi.mocked(child_process.execFile).mock.calls[0][1] as string[]
expect(callArgs).not.toContain('-maxrate')
expect(callArgs).not.toContain('-bufsize')
})
it('transcodeVideo with hardwareAcceleration auto and nvenc should use -preset p4, -rc:v vbr, -cq:v 26, -b:v 0, and -maxrate', async () => {
@@ -1694,7 +1696,9 @@ describe('TranscodeService', () => {
'-preset',
'fast',
'-crf',
'26',
'23',
'-bf',
'0',
'-b:v',
'1500k',
'-pix_fmt',
@@ -1813,4 +1817,477 @@ describe('TranscodeService', () => {
)
})
})
describe('HDR detection, tone mapping, and transcoding', () => {
it('buildSdrToneMapFilterChain constructs zscale + tonemap filter chain for PQ and HLG', () => {
const available = new Set(['zscale', 'tonemap'])
const pqChain = buildSdrToneMapFilterChain({
hdrType: 'pq',
availableFilters: available,
})
expect(pqChain).toContain(
'setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc',
)
expect(pqChain).toContain('zscale=tin=smpte2084:pin=bt2020:min=bt2020nc')
expect(pqChain).toContain('tonemap=tonemap=hable:desat=0:peak=100')
expect(pqChain).toContain('format=yuv420p')
const hlgChain = buildSdrToneMapFilterChain({
hdrType: 'hlg',
availableFilters: available,
})
expect(hlgChain).toContain(
'setparams=color_primaries=bt2020:color_trc=arib-std-b67:colorspace=bt2020nc',
)
expect(hlgChain).toContain('zscale=tin=arib-std-b67:pin=bt2020:min=bt2020nc')
expect(hlgChain).toContain('tonemap=tonemap=hable')
})
it('buildSdrToneMapFilterChain throws error if zscale or tonemap is missing for PQ/HLG', () => {
expect(() =>
buildSdrToneMapFilterChain({
hdrType: 'pq',
availableFilters: new Set(['zscale']),
}),
).toThrow(/zscale and tonemap filters are required for HDR tone mapping/)
expect(() =>
buildSdrToneMapFilterChain({
hdrType: 'hlg',
availableFilters: new Set(['tonemap']),
}),
).toThrow(/zscale and tonemap filters are required for HDR tone mapping/)
})
it('buildSdrToneMapFilterChain constructs zscale + tonemap filter chain for Dolby Vision Profile 5', () => {
const chain = buildSdrToneMapFilterChain({
hdrType: 'dovi_p5',
availableFilters: new Set(['zscale', 'tonemap']),
})
expect(chain).toContain(
'setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc',
)
expect(chain).toContain('tin=smpte2084')
expect(chain).toContain('tonemap=tonemap=hable')
expect(chain).toContain('m=bt709')
})
it('buildSdrToneMapFilterChain throws error if zscale or tonemap is missing for Dolby Vision Profile 5', () => {
expect(() =>
buildSdrToneMapFilterChain({
hdrType: 'dovi_p5',
availableFilters: new Set(['tonemap']),
}),
).toThrow(/zscale and tonemap filters are required for HDR tone mapping/)
})
const mockExecFileStdout = (mockOutput: string) => {
;(
child_process.execFile as unknown as {
mockImplementation: (
fn: (
file: string,
args: string[],
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
) => unknown,
) => void
}
).mockImplementation((_file, _args, cb) => {
cb(null, { stdout: mockOutput, stderr: '' })
})
}
it('getVideoInfo detects PQ HDR from smpte2084 color_transfer', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'hevc',
width: 3840,
height: 2160,
r_frame_rate: '24/1',
color_transfer: 'smpte2084',
color_primaries: 'bt2020',
color_space: 'bt2020nc',
bits_per_raw_sample: '10',
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('hdr-pq.mp4')
expect(info.isHdr).toBe(true)
expect(info.hdrType).toBe('pq')
expect(info.colorTransfer).toBe('smpte2084')
})
it('getVideoInfo detects HLG HDR from arib-std-b67 color_transfer', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'hevc',
width: 1920,
height: 1080,
r_frame_rate: '30/1',
color_transfer: 'arib-std-b67',
color_primaries: 'bt2020',
color_space: 'bt2020nc',
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('hdr-hlg.mp4')
expect(info.isHdr).toBe(true)
expect(info.hdrType).toBe('hlg')
expect(info.colorTransfer).toBe('arib-std-b67')
})
it('getVideoInfo treats 10-bit Rec.709 with BT.709 transfer as SDR', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'h264',
width: 1920,
height: 1080,
r_frame_rate: '24/1',
color_transfer: 'bt709',
color_primaries: 'bt709',
color_space: 'bt709',
bits_per_raw_sample: '10',
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('10bit-sdr.mp4')
expect(info.isHdr).toBe(false)
expect(info.hdrType).toBe('sdr')
})
it('getVideoInfo detects Dolby Vision Profile 5 via side data', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '25000000' },
streams: [
{
codec_type: 'video',
codec_name: 'hevc',
width: 3840,
height: 2160,
r_frame_rate: '24/1',
side_data_list: [
{
side_data_type: 'DOVI configuration record',
dv_profile: 5,
dv_level: 6,
},
],
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('dovi-p5.mp4')
expect(info.isHdr).toBe(true)
expect(info.hdrType).toBe('dovi_p5')
expect(info.dvProfile).toBe(5)
})
it('getVideoInfo treats Dolby Vision Profile 8 with BT.709 transfer as SDR', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '25000000' },
streams: [
{
codec_type: 'video',
codec_name: 'hevc',
width: 1920,
height: 1080,
r_frame_rate: '24/1',
color_transfer: 'bt709',
color_primaries: 'bt709',
color_space: 'bt709',
side_data_list: [
{
side_data_type: 'DOVI configuration record',
dv_profile: 8,
},
],
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('dovi-p8-sdr.mp4')
expect(info.isHdr).toBe(false)
expect(info.hdrType).toBe('sdr')
expect(info.dvProfile).toBe(8)
})
it('getVideoInfo swaps width and height when Display Matrix side data has rotation -90', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'hevc',
width: 1920,
height: 1080,
r_frame_rate: '30/1',
side_data_list: [
{
side_data_type: 'Display Matrix',
rotation: -90,
},
],
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('vertical-display-matrix.mp4')
expect(info.originalWidth).toBe(1080)
expect(info.originalHeight).toBe(1920)
expect(info.rotation).toBe(-90)
})
it('getVideoInfo swaps width and height when tags.rotate is 90 or 270', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'h264',
width: 1920,
height: 1080,
r_frame_rate: '30/1',
tags: {
rotate: '90',
},
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('vertical-tag.mp4')
expect(info.originalWidth).toBe(1080)
expect(info.originalHeight).toBe(1920)
expect(info.rotation).toBe(90)
})
it('getVideoInfo preserves width and height when rotation is 180 degrees', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'h264',
width: 1920,
height: 1080,
r_frame_rate: '30/1',
tags: {
rotate: '180',
},
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('upside-down.mp4')
expect(info.originalWidth).toBe(1920)
expect(info.originalHeight).toBe(1080)
expect(info.rotation).toBe(180)
})
it('transcodeVideo preserves HDR parameters and tags when hdr is true', async () => {
let executedArgs: string[] = []
;(
child_process.execFile as unknown as {
mockImplementation: (
fn: (
file: string,
args: string[],
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
) => unknown,
) => void
}
).mockImplementation((_file, args, cb) => {
if (args.includes('-filters')) {
cb(null, { stdout: ' ... zscale ... \n ... tonemap ... ', stderr: '' })
return {}
}
if (args.includes('-encoders')) {
cb(null, { stdout: ' V..... libx264 ', stderr: '' })
return {}
}
executedArgs = args
cb(null, { stdout: '', stderr: '' })
return {}
})
const outputFile = path.join(tempDir, 'hdr_output.mp4')
await transcodeService.transcodeVideo({
inputFile: 'hdr_input.mp4',
outputFile,
width: 1920,
height: 1080,
hdr: true,
sourceIsHdr: true,
sourceHdrType: 'pq',
sourceColorTransfer: 'smpte2084',
})
expect(executedArgs).toContain('-color_primaries')
expect(executedArgs).toContain('bt2020')
expect(executedArgs).toContain('-color_trc')
expect(executedArgs).toContain('smpte2084')
expect(executedArgs).toContain('-colorspace')
expect(executedArgs).toContain('bt2020nc')
expect(executedArgs).toContain('-x264-params')
expect(executedArgs).toContain('colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc')
})
it('transcodeVideo transcodes Dolby Vision Profile 5 to HDR proxy without libplacebo', async () => {
let executedArgs: string[] = []
;(
child_process.execFile as unknown as {
mockImplementation: (
fn: (
file: string,
args: string[],
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
) => unknown,
) => void
}
).mockImplementation((_file, args, cb) => {
if (args.includes('-filters')) {
cb(null, { stdout: ' ... zscale ... \n ... tonemap ... ', stderr: '' })
return {}
}
if (args.includes('-encoders')) {
cb(null, { stdout: ' V..... libx264 ', stderr: '' })
return {}
}
executedArgs = args
cb(null, { stdout: '', stderr: '' })
return {}
})
const outputFile = path.join(tempDir, 'dovi_p5_hdr.mp4')
await transcodeService.transcodeVideo({
inputFile: 'dovi_p5_input.mp4',
outputFile,
width: 1920,
height: 1080,
hdr: true,
sourceIsHdr: true,
sourceHdrType: 'dovi_p5',
})
const filterIdx = executedArgs.indexOf('-filter_complex')
expect(filterIdx).toBeGreaterThan(-1)
const filterComplex = executedArgs[filterIdx + 1]
expect(filterComplex).not.toContain('libplacebo')
expect(executedArgs).toContain('-color_primaries')
expect(executedArgs).toContain('bt2020')
expect(executedArgs).toContain('-color_trc')
expect(executedArgs).toContain('smpte2084')
})
it('generateSprite uses split=2 filterComplex for HDR inputs', async () => {
let executedArgs: string[] = []
;(
child_process.execFile as unknown as {
mockImplementation: (
fn: (
file: string,
args: string[],
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
) => unknown,
) => void
}
).mockImplementation((_file, args, cb) => {
if (args.includes('-filters')) {
cb(null, { stdout: ' ... zscale ... \n ... tonemap ... ', stderr: '' })
return {}
}
executedArgs = args
cb(null, { stdout: '', stderr: '' })
return {}
})
const spritePath = path.join(tempDir, 'sprite.webp')
const posterPath = path.join(tempDir, 'poster.webp')
await transcodeService.generateSprite('input.mp4', spritePath, posterPath, 100, undefined, {
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
})
const filterIdx = executedArgs.indexOf('-filter_complex')
expect(filterIdx).toBeGreaterThan(-1)
const filterStr = executedArgs[filterIdx + 1]
expect(filterStr).toContain('split=2[v_sprite][v_thumb]')
expect(filterStr).toContain('[v_sprite]fps=')
expect(filterStr).toContain('[v_thumb]scale=')
})
it('generateSprite uses split=2 filterComplex for SDR inputs', async () => {
let executedArgs: string[] = []
;(
child_process.execFile as unknown as {
mockImplementation: (
fn: (
file: string,
args: string[],
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
) => unknown,
) => void
}
).mockImplementation((_file, args, cb) => {
executedArgs = args
cb(null, { stdout: '', stderr: '' })
return {}
})
const spritePath = path.join(tempDir, 'sprite.webp')
const posterPath = path.join(tempDir, 'poster.webp')
await transcodeService.generateSprite('input.mp4', spritePath, posterPath, 100)
const filterIdx = executedArgs.indexOf('-filter_complex')
expect(filterIdx).toBeGreaterThan(-1)
const filterStr = executedArgs[filterIdx + 1]
expect(filterStr).toContain('[0:v]split=2[v_sprite][v_thumb]')
expect(filterStr).toContain('[v_sprite]fps=')
expect(filterStr).toContain('[v_thumb]scale=')
})
})
})
+239 -19
View File
@@ -87,6 +87,8 @@ export function parseCsvContent(content: string): string[][] {
}
}
export type HdrType = 'pq' | 'hlg' | 'dovi_p5' | 'dovi_p8' | 'sdr'
export interface MediaMetadata {
originalWidth: number
originalHeight: number
@@ -103,6 +105,14 @@ export interface MediaMetadata {
audioSampleRate?: number
audioBitDepth?: number
mimeType: string
colorTransfer?: string
colorPrimaries?: string
colorSpace?: string
isHdr?: boolean
hdrType?: HdrType
dvProfile?: number
dvCompatibilityId?: number
rotation?: number
}
export interface TranscodeVideoParams {
@@ -118,6 +128,12 @@ export interface TranscodeVideoParams {
sourceVideoBitrate?: number
threads?: number
signal?: AbortSignal
hdr?: boolean
sourceIsHdr?: boolean
sourceHdrType?: HdrType
sourceColorTransfer?: string
sourceColorPrimaries?: string
sourceColorSpace?: string
}
export interface EncoderConfig {
@@ -140,11 +156,11 @@ export const H264_ENCODER_CONFIGS: Record<string, EncoderConfig> = {
},
h264_videotoolbox: {
name: 'h264_videotoolbox',
presetArgs: ['-q:v', '74'],
presetArgs: [],
},
libx264: {
name: 'libx264',
presetArgs: ['-preset', 'fast', '-crf', '26'],
presetArgs: ['-preset', 'fast', '-crf', '23', '-bf', '0'],
},
}
@@ -180,12 +196,12 @@ export function getDefaultBitrate(height: number, width?: number): string {
return `${Math.round(bps / 1000)}k`
}
export function calculateMaxBitrate(
export function calculateEffectiveBitrateBps(
targetHeight: number,
targetWidth?: number,
sourceVideoBitrate?: number,
targetFps?: number | string,
): { maxrate: string; bufsize: string } {
): number {
let configuredMaxBps = getDefaultBitrateBps(targetHeight, targetWidth)
// If frame rate is downsampled (e.g. 180p preview with < 24 fps), scale the bitrate ceiling proportionally
@@ -207,13 +223,27 @@ export function calculateMaxBitrate(
}
}
let effectiveMaxBps =
const effectiveMaxBps =
sourceVideoBitrate && sourceVideoBitrate > 0
? Math.min(configuredMaxBps, Math.round(sourceVideoBitrate * 1.2))
: configuredMaxBps
const minFloor = targetFps ? 50_000 : 100_000
effectiveMaxBps = Math.max(minFloor, effectiveMaxBps)
return Math.max(minFloor, effectiveMaxBps)
}
export function calculateMaxBitrate(
targetHeight: number,
targetWidth?: number,
sourceVideoBitrate?: number,
targetFps?: number | string,
): { maxrate: string; bufsize: string } {
const effectiveMaxBps = calculateEffectiveBitrateBps(
targetHeight,
targetWidth,
sourceVideoBitrate,
targetFps,
)
const maxrateKbps = Math.max(50, Math.round(effectiveMaxBps / 1000))
const bufsizeKbps = maxrateKbps * 2
@@ -224,6 +254,24 @@ export function calculateMaxBitrate(
}
}
export function buildSdrToneMapFilterChain(options: {
hdrType?: HdrType
availableFilters?: Set<string>
colorTransfer?: string
}): string {
if (options.availableFilters) {
if (!options.availableFilters.has('zscale') || !options.availableFilters.has('tonemap')) {
throw new Error('zscale and tonemap filters are required for HDR tone mapping')
}
}
const tin =
options.hdrType === 'hlg' || options.colorTransfer === 'arib-std-b67'
? 'arib-std-b67'
: 'smpte2084'
return `setparams=color_primaries=bt2020:color_trc=${tin}:colorspace=bt2020nc,zscale=tin=${tin}:pin=bt2020:min=bt2020nc:t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0:peak=100,zscale=t=bt709:m=bt709:out_range=full,format=yuv420p`
}
export interface ExtractVideoFramesParams {
inputFile: string
outputDir: string
@@ -432,9 +480,101 @@ export class TranscodeService {
}
}
const colorTransfer =
typeof videoStream.color_transfer === 'string'
? videoStream.color_transfer.toLowerCase()
: undefined
const colorPrimaries =
typeof videoStream.color_primaries === 'string'
? videoStream.color_primaries.toLowerCase()
: undefined
const colorSpace =
typeof videoStream.color_space === 'string'
? videoStream.color_space.toLowerCase()
: undefined
let dvProfile: number | undefined
let dvCompatibilityId: number | undefined
if (Array.isArray(videoStream.side_data_list)) {
const dovi = videoStream.side_data_list.find(
(sd: unknown): sd is Record<string, unknown> =>
typeof (sd as Record<string, unknown>)?.side_data_type === 'string' &&
String((sd as Record<string, unknown>).side_data_type)
.toLowerCase()
.includes('dovi'),
)
if (dovi) {
dvProfile = this.safeParseInt(dovi.dv_profile)
dvCompatibilityId = this.safeParseInt(dovi.dv_bl_signal_compatibility_id)
}
}
let isHdr: boolean
let hdrType: HdrType
if (dvProfile === 5) {
isHdr = true
hdrType = 'dovi_p5'
} else if (dvProfile !== undefined) {
if (colorTransfer === 'smpte2084') {
isHdr = true
hdrType = 'pq'
} else if (colorTransfer === 'arib-std-b67') {
isHdr = true
hdrType = 'hlg'
} else {
isHdr = false
hdrType = 'sdr'
}
} else {
if (colorTransfer === 'smpte2084') {
isHdr = true
hdrType = 'pq'
} else if (colorTransfer === 'arib-std-b67') {
isHdr = true
hdrType = 'hlg'
} else {
isHdr = false
hdrType = 'sdr'
}
}
let rotation = 0
if (Array.isArray(videoStream.side_data_list)) {
const displayMatrix = videoStream.side_data_list.find(
(sd: unknown): sd is Record<string, unknown> =>
typeof (sd as Record<string, unknown>)?.side_data_type === 'string' &&
String((sd as Record<string, unknown>).side_data_type).toLowerCase() === 'display matrix',
)
if (displayMatrix && typeof displayMatrix.rotation === 'number') {
rotation = displayMatrix.rotation
}
}
if (!rotation) {
const rotateTag = videoStream.tags?.rotate || info.format?.tags?.rotate
if (rotateTag) {
const parsed = parseFloat(rotateTag)
if (Number.isFinite(parsed)) {
rotation = parsed
}
}
}
const normalizedRotation = ((Math.round(rotation) % 360) + 360) % 360
const isRotatedVertical = normalizedRotation === 90 || normalizedRotation === 270
const rawWidth = typeof videoStream.width === 'number' ? videoStream.width : 0
const rawHeight = typeof videoStream.height === 'number' ? videoStream.height : 0
const originalWidth = isRotatedVertical ? rawHeight : rawWidth
const originalHeight = isRotatedVertical ? rawWidth : rawHeight
return {
originalWidth: videoStream.width,
originalHeight: videoStream.height,
originalWidth,
originalHeight,
rotation: rotation || undefined,
duration,
bitRate: parseFloat(info.format.bit_rate),
videoBitRate,
@@ -450,6 +590,13 @@ export class TranscodeService {
this.safeParseInt(audioStream?.bits_per_raw_sample) ??
this.safeParseInt(audioStream?.bits_per_sample),
mimeType: '',
colorTransfer,
colorPrimaries,
colorSpace,
isHdr,
hdrType,
dvProfile,
dvCompatibilityId,
}
}
@@ -539,6 +686,34 @@ export class TranscodeService {
}
}
private availableFiltersCache: Set<string> | null = null
clearFiltersCache(): void {
this.availableFiltersCache = null
}
async getAvailableFilters(): Promise<Set<string>> {
if (this.availableFiltersCache) {
return this.availableFiltersCache
}
try {
const { stdout } = await execFileAsync('ffmpeg', ['-filters'])
const filters = new Set<string>()
const lines = stdout.split('\n')
for (const line of lines) {
const match = line.match(/^\s*[A-Z.]{2,4}\s+([a-zA-Z0-9_-]+)/)
if (match) {
filters.add(match[1])
}
}
this.availableFiltersCache = filters
return filters
} catch (err) {
console.warn('Failed to probe ffmpeg filters:', err)
return new Set<string>()
}
}
async selectH264Encoder(
hardwareAcceleration?: 'off' | 'auto',
platform: NodeJS.Platform = process.platform,
@@ -559,14 +734,22 @@ export class TranscodeService {
}
async transcodeVideo(params: TranscodeVideoParams): Promise<void> {
const isSourceHdr =
params.sourceIsHdr ||
params.sourceHdrType === 'pq' ||
params.sourceHdrType === 'hlg' ||
params.sourceHdrType === 'dovi_p5'
const isHdrOutput = Boolean(params.hdr)
let filterComplex: string
const args: string[] = ['-i', params.inputFile]
const baseScale = `scale=w=${params.width}:h=${params.height}:force_original_aspect_ratio=decrease,scale=w='trunc(iw/2)*2':h='trunc(ih/2)*2'`
if (params.overlayFile) {
args.push('-i', params.overlayFile)
filterComplex = `[0:v]scale=${params.width}:${params.height}[vscaled];[vscaled][1:v]overlay=0:0`
} else {
filterComplex = `[0:v]scale=w=${params.width}:h=${params.height}:force_original_aspect_ratio=decrease,scale=w='trunc(iw/2)*2':h='trunc(ih/2)*2'`
filterComplex = `[0:v]${baseScale}`
}
if (params.frameRate) {
@@ -611,20 +794,44 @@ export class TranscodeService {
args.push(...encoder.presetArgs)
}
if (params.videoBitrate) {
args.push('-b:v', params.videoBitrate)
if (encoder.name === 'h264_videotoolbox') {
if (params.videoBitrate) {
args.push('-b:v', params.videoBitrate)
} else {
const targetBps = calculateEffectiveBitrateBps(
params.height,
params.width,
params.sourceVideoBitrate,
params.frameRate,
)
const targetKbps = Math.max(50, Math.round(targetBps / 1000))
args.push('-b:v', `${targetKbps}k`)
}
} else {
const { maxrate, bufsize } = calculateMaxBitrate(
params.height,
params.width,
params.sourceVideoBitrate,
params.frameRate,
)
args.push('-maxrate', maxrate, '-bufsize', bufsize)
if (params.videoBitrate) {
args.push('-b:v', params.videoBitrate)
} else {
const { maxrate, bufsize } = calculateMaxBitrate(
params.height,
params.width,
params.sourceVideoBitrate,
params.frameRate,
)
args.push('-maxrate', maxrate, '-bufsize', bufsize)
}
}
args.push('-pix_fmt', 'yuv420p')
if (isSourceHdr && isHdrOutput) {
const isHlg = params.sourceHdrType === 'hlg' || params.sourceColorTransfer === 'arib-std-b67'
const trc = isHlg ? 'arib-std-b67' : 'smpte2084'
args.push('-color_primaries', 'bt2020', '-color_trc', trc, '-colorspace', 'bt2020nc')
if (encoder.name === 'libx264') {
args.push('-x264-params', `colorprim=bt2020:transfer=${trc}:colormatrix=bt2020nc`)
}
}
if (!params.disableAudio) {
args.push('-c:a', 'aac', '-b:a', '128k')
}
@@ -749,9 +956,22 @@ export class TranscodeService {
outputPoster: string,
duration: number,
signal?: AbortSignal,
hdrOptions?: { isHdr?: boolean; hdrType?: HdrType; colorTransfer?: string },
): Promise<void> {
const spriteFps = 100 / duration
const filterComplex = `[0:v]fps=${spriteFps},scale=w=300:h=-2,tile=10x10[sprite_out];[0:v]scale=-2:300:force_original_aspect_ratio=decrease,select='eq(n\\,0)'[thumb_out]`
let filterComplex: string
if (hdrOptions?.isHdr) {
const availableFilters = await this.getAvailableFilters()
const tonemap = buildSdrToneMapFilterChain({
hdrType: hdrOptions.hdrType,
colorTransfer: hdrOptions.colorTransfer,
availableFilters,
})
filterComplex = `[0:v]${tonemap},split=2[v_sprite][v_thumb];[v_sprite]fps=${spriteFps},scale=w=300:h=-2,tile=10x10[sprite_out];[v_thumb]scale=-2:300:force_original_aspect_ratio=decrease,select='eq(n\\,0)'[thumb_out]`
} else {
filterComplex = `[0:v]split=2[v_sprite][v_thumb];[v_sprite]fps=${spriteFps},scale=w=300:h=-2,tile=10x10[sprite_out];[v_thumb]scale=-2:300:force_original_aspect_ratio=decrease,select='eq(n\\,0)'[thumb_out]`
}
const args = [
'-i',
+36 -3
View File
@@ -67,15 +67,26 @@ describe('handleDaemonCommands', () => {
}
})
it('runs the runFn on normal startup', async () => {
it('runs the runFn on normal foreground startup without creating a PID file', async () => {
process.argv = ['node', 'script.js']
const runFn = vi.fn().mockResolvedValue(undefined)
await handleDaemonCommands(appName, runFn)
expect(runFn).toHaveBeenCalled()
expect(existsSync(pidFile)).toBe(true)
expect(readFileSync(pidFile, 'utf8').trim()).toBe(process.pid.toString())
expect(existsSync(pidFile)).toBe(false)
})
it('runs foreground startup even if a stale or conflicting PID file exists', async () => {
process.argv = ['node', 'script.js']
const runFn = vi.fn().mockResolvedValue(undefined)
mkdirSync(join(mockTempDir, '.shumai', 'pids'), { recursive: true })
writeFileSync(pidFile, '12345')
await handleDaemonCommands(appName, runFn)
expect(runFn).toHaveBeenCalled()
})
it('stops the process if stop command is passed', async () => {
@@ -122,4 +133,26 @@ describe('handleDaemonCommands', () => {
expect(spawn).toHaveBeenCalled()
expect(mockExit).toHaveBeenCalledWith(0)
})
it('runs and manages PID file when running as a daemonized child', async () => {
process.argv = ['node', 'script.js']
const originalEnv = process.env.SHUMAI_DAEMONIZED
process.env.SHUMAI_DAEMONIZED = 'true'
try {
const runFn = vi.fn().mockResolvedValue(undefined)
await handleDaemonCommands(appName, runFn)
expect(runFn).toHaveBeenCalled()
expect(existsSync(pidFile)).toBe(true)
expect(readFileSync(pidFile, 'utf8').trim()).toBe(process.pid.toString())
} finally {
if (originalEnv !== undefined) {
process.env.SHUMAI_DAEMONIZED = originalEnv
} else {
delete process.env.SHUMAI_DAEMONIZED
}
}
})
})
+19 -29
View File
@@ -17,6 +17,9 @@ const PID_DIR = join(SHUMAI_DIR, 'pids')
const LOG_DIR = join(SHUMAI_DIR, 'logs')
function isProcessRunning(pid: number): boolean {
if (pid <= 1) {
return false
}
try {
process.kill(pid, 0)
return true
@@ -35,7 +38,7 @@ async function stopProcess(appName: string, pidFile: string): Promise<boolean> {
}
const pid = parseInt(readFileSync(pidFile, 'utf8').trim(), 10)
if (isNaN(pid)) {
if (isNaN(pid) || pid <= 1) {
console.log(`Invalid PID found in ${pidFile}. Cleaning up file.`)
try {
unlinkSync(pidFile)
@@ -180,18 +183,25 @@ export async function handleDaemonCommands(
appName: string,
runFn: () => Promise<void>,
): Promise<void> {
const pidFile = join(PID_DIR, `${appName}.pid`)
const logFile = join(LOG_DIR, `${appName}.log`)
// Ensure directories exist
mkdirSync(PID_DIR, { recursive: true })
mkdirSync(LOG_DIR, { recursive: true })
const args = process.argv.slice(2)
const isStop = args.includes('stop')
const isRestart = args.includes('restart')
const isLogs = args.includes('logs')
const isDaemon = args.includes('-d') && process.env.SHUMAI_DAEMONIZED !== 'true'
const isDaemonizedChild = process.env.SHUMAI_DAEMONIZED === 'true'
// Normal foreground startup: do not create, check, or track PID files
if (!isStop && !isRestart && !isLogs && !isDaemon && !isDaemonizedChild) {
await runFn()
return
}
const pidFile = join(PID_DIR, `${appName}.pid`)
const logFile = join(LOG_DIR, `${appName}.log`)
// Ensure directories exist for daemon commands
mkdirSync(PID_DIR, { recursive: true })
mkdirSync(LOG_DIR, { recursive: true })
if (isStop) {
await stopProcess(appName, pidFile)
@@ -216,27 +226,7 @@ export async function handleDaemonCommands(
process.exit(0)
}
// Normal Startup logic: check if already running
if (existsSync(pidFile)) {
const pid = parseInt(readFileSync(pidFile, 'utf8').trim(), 10)
if (!isNaN(pid) && pid !== process.pid) {
if (isProcessRunning(pid)) {
console.error(
`${appName} is already running (PID: ${pid}). Use '${appName} stop' or '${appName} restart'.`,
)
process.exit(1)
} else {
// Process is dead, clean up PID file
try {
unlinkSync(pidFile)
} catch {
// Ignore
}
}
}
}
// Write the PID file
// Daemonized child startup (SHUMAI_DAEMONIZED === 'true')
writeFileSync(pidFile, process.pid.toString(), 'utf8')
const cleanPidFile = () => {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/db",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+9
View File
@@ -50,6 +50,7 @@ declare global {
// ----------------------------------------------------------------------
export type VideoTranscodeStrategy = 'best_match' | 'all'
export type HardwareAcceleration = 'off' | 'auto'
export type HdrType = 'pq' | 'hlg' | 'dovi_p5' | 'dovi_p8' | 'sdr'
// ----------------------------------------------------------------------
// Collection Filter
@@ -104,6 +105,7 @@ declare global {
width: number
height: number
resolution?: string
hdr?: boolean
}
export interface ImageTranscode {
@@ -130,6 +132,7 @@ declare global {
export interface Metadata {
originalHeight: number
originalWidth: number
rotation?: number
hasAudio: boolean
duration: number
bitRate: number
@@ -142,6 +145,12 @@ declare global {
audioChannels?: number
audioSampleRate?: number
audioBitDepth?: number
colorTransfer?: string
colorPrimaries?: string
colorSpace?: string
isHdr?: boolean
hdrType?: HdrType
dvProfile?: number
format: unknown
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/dtos",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+4
View File
@@ -18,6 +18,7 @@ export const previewInfoSchema = z.object({
thumbnailUrl: z.string().optional(),
originalHeight: z.number().optional(),
originalWidth: z.number().optional(),
rotation: z.number().optional(),
spriteUrl: z.string().optional(),
duration: z.number().optional(),
pageCount: z.number().optional(),
@@ -60,6 +61,7 @@ export const mediaMetadataSchema = z.object({
duration: z.number().optional(),
originalWidth: z.number().optional(),
originalHeight: z.number().optional(),
rotation: z.number().optional(),
frameRate: z.number().optional(),
totalFrames: z.number().optional(),
startTimecode: z.string().optional(),
@@ -103,6 +105,7 @@ export const assetInfoSchema = z.object({
width: z.number(),
height: z.number(),
size: z.number(),
hdr: z.boolean().optional(),
}),
)
.optional(),
@@ -335,6 +338,7 @@ export interface VideoTranscode {
width: number
height: number
size: number
hdr?: boolean
}
export const postAttachmentRequestSchema = z.object({
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/e2e",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/tableprinter",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/transcode",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
@@ -75,6 +75,7 @@ vi.mock('@shumai/core/src/transcode/transcode', async (importOriginal) => {
takeScreenshots: vi.fn(),
overlayAnnotations: vi.fn(),
renderPdfPages: vi.fn(),
getAvailableFilters: vi.fn().mockResolvedValue(new Set(['zscale', 'tonemap'])),
},
}
})
@@ -184,6 +185,7 @@ describe('Transcode Activities', () => {
audioChannels: 2,
audioSampleRate: 48000,
audioBitDepth: 16,
rotation: -90,
mimeType: 'video/mp4',
})
@@ -197,6 +199,7 @@ describe('Transcode Activities', () => {
expect(transcodeService.getVideoInfo).toHaveBeenCalledWith('/tmp/v.mp4')
expect(result.duration).toBe(10)
expect(result.metadata?.originalWidth).toBe(1920)
expect(result.metadata?.rotation).toBe(-90)
expect(result.metadata?.videoBitRate).toBe(850000)
expect(result.metadata?.videoCodec).toBe('Advanced Video Coding')
expect(result.metadata?.audioCodec).toBe('MPEG-4 Audio')
@@ -205,7 +208,10 @@ describe('Transcode Activities', () => {
expect(result.metadata?.audioBitDepth).toBe(16)
expect(metadataService.updateAssetMetadata).toHaveBeenCalledWith(
asset.id,
expect.arrayContaining([{ key: 'file_type', value: 'video' }]),
expect.arrayContaining([
{ key: 'file_type', value: 'video' },
{ key: 'rotation', value: -90 },
]),
true,
)
})
@@ -696,6 +702,37 @@ describe('Transcode Activities', () => {
)
})
it('transcodeVideoActivity appends -hdr.mp4 suffix and forwards HDR metadata', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
const result = await transcodeVideoActivity({
assetKey: 'files/asset-1/video.mp4',
filePath: '/tmp/video.mp4',
videoSpec: { resolution: '1080p', width: 1920, height: 1080, hdr: true },
duration: 10,
originalFps: 30,
sourceIsHdr: true,
sourceHdrType: 'pq',
sourceColorTransfer: 'smpte2084',
sourceColorPrimaries: 'bt2020',
sourceColorSpace: 'bt2020nc',
})
expect(result.key).toBe('files/asset-1/video-1080p-hdr.mp4')
expect(result.hdr).toBe(true)
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
expect.objectContaining({
inputFile: '/tmp/video.mp4',
hdr: true,
sourceIsHdr: true,
sourceHdrType: 'pq',
sourceColorTransfer: 'smpte2084',
sourceColorPrimaries: 'bt2020',
sourceColorSpace: 'bt2020nc',
}),
)
})
it('should call transcodeService.takeScreenshots', async () => {
vi.mocked(transcodeService.takeScreenshots).mockResolvedValue([
{ key: 'screenshots/shot1.webp', timestamp: 1.0 },
@@ -873,6 +910,44 @@ describe('Transcode Activities', () => {
).rejects.toThrowError(/Sprite\/Poster generation failed/)
})
it('generateSpriteActivity forwards HDR options to transcodeService.generateSprite', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
vi.mocked(transcodeService.generateSprite).mockImplementation(
async (_in, spriteOut, posterOut) => {
fs.writeFileSync(spriteOut, Buffer.from('fake-sprite'))
fs.writeFileSync(posterOut, Buffer.from('fake-poster'))
},
)
await generateSpriteActivity({
assetKey: 'files/asset-1/video.mp4',
filePath: '/tmp/video.mp4',
mediaInfo: {
duration: 10,
metadata: {
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
},
} as unknown as PrismaJson.MediaInfo,
spriteSpec: { key: 'files/asset-1/sprite.webp', frames: 100, tileX: 10, tileY: 10 },
posterSpec: { key: 'files/asset-1/poster.webp' },
})
expect(transcodeService.generateSprite).toHaveBeenCalledWith(
'/tmp/video.mp4',
expect.any(String),
expect.any(String),
10,
undefined,
{
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
},
)
})
it('should throw non-retryable ApplicationFailure when takeScreenshotsActivity fails with error', async () => {
vi.mocked(transcodeService.takeScreenshots).mockRejectedValue(new Error('FFmpeg failed'))
@@ -1100,6 +1175,41 @@ describe('Transcode Activities', () => {
)
})
it('extractPosterActivity applies tone mapping filter when isHdr is true', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
vi.mocked(s3Service.resolveInput).mockResolvedValue('https://mock-r2.com/video.mp4')
let ffmpegArgs: string[] = []
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(child_process.execFile as any).mockImplementation(
(file: string, args: string[], optionsOrCb: unknown, maybeCb?: unknown) => {
const cb = typeof optionsOrCb === 'function' ? optionsOrCb : maybeCb
if (file === 'ffmpeg') {
ffmpegArgs = args
const outPath = args[args.length - 1]
fs.writeFileSync(outPath, 'fake-poster-bytes')
}
if (typeof cb === 'function') {
cb(null, { stdout: '', stderr: '' })
}
},
)
await extractPosterActivity({
assetKey: 'video.mp4',
posterSpec: { key: 'files/asset-1/poster.webp' },
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
})
const vfIndex = ffmpegArgs.indexOf('-vf')
expect(vfIndex).toBeGreaterThan(-1)
const vfArg = ffmpegArgs[vfIndex + 1]
expect(vfArg).toContain('zscale=tin=smpte2084')
expect(vfArg).toContain('tonemap=tonemap=hable')
expect(vfArg).toContain('scale=-2:300')
})
it('should throw non-retryable ApplicationFailure when poster extraction is cancelled with aborted signal', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
const controller = new AbortController()
+61 -7
View File
@@ -1,6 +1,10 @@
import { AssetStatus, prisma, WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
import { s3Service } from '@shumai/core/src/s3/s3'
import { transcodeService } from '@shumai/core/src/transcode/transcode'
import {
transcodeService,
buildSdrToneMapFilterChain,
type HdrType,
} from '@shumai/core/src/transcode/transcode'
import { metadataService } from '@shumai/core/src/metadata/metadata'
import { getDerivedArtifactDirectory, stemFromKey } from '@shumai/core/src/utils/filename'
import { gotenbergService } from '@shumai/core/src/gotenberg/gotenberg'
@@ -142,6 +146,13 @@ export async function getMediaInfoActivity(params: {
audioChannels: info.audioChannels,
audioSampleRate: info.audioSampleRate,
audioBitDepth: info.audioBitDepth,
colorTransfer: info.colorTransfer,
colorPrimaries: info.colorPrimaries,
colorSpace: info.colorSpace,
isHdr: info.isHdr,
hdrType: info.hdrType,
dvProfile: info.dvProfile,
rotation: info.rotation,
format: {},
}
metadataUpdates.push(
@@ -151,6 +162,12 @@ export async function getMediaInfoActivity(params: {
{ key: 'bitRate', value: info.bitRate / 1000 },
{ key: 'frame_rate', value: info.frameRate },
)
if (info.rotation !== undefined)
metadataUpdates.push({ key: 'rotation', value: info.rotation })
if (info.isHdr !== undefined)
metadataUpdates.push({ key: 'is_hdr', value: info.isHdr ? 1 : 0 })
if (info.colorTransfer)
metadataUpdates.push({ key: 'color_transfer', value: info.colorTransfer })
if (info.videoCodec) metadataUpdates.push({ key: 'video_codec', value: info.videoCodec })
if (info.audioCodec) metadataUpdates.push({ key: 'audio_codec', value: info.audioCodec })
if (info.audioChannels !== undefined)
@@ -253,6 +270,11 @@ export interface VideoActivityParams {
hardwareAcceleration?: PrismaJson.HardwareAcceleration
sourceVideoBitrate?: number
threads?: number
sourceIsHdr?: boolean
sourceHdrType?: HdrType
sourceColorTransfer?: string
sourceColorPrimaries?: string
sourceColorSpace?: string
}
export async function transcodeVideoActivity(
@@ -261,7 +283,8 @@ export async function transcodeVideoActivity(
const bucket = process.env.S3_BUCKET || 'shumai'
const stem = stemFromKey(params.assetKey)
const res = params.videoSpec.resolution || `${params.videoSpec.height}p`
const key = path.posix.join(path.posix.dirname(params.assetKey), `${stem}-${res}.mp4`)
const suffix = params.videoSpec.hdr ? `${res}-hdr` : res
const key = path.posix.join(path.posix.dirname(params.assetKey), `${stem}-${suffix}.mp4`)
const signal = getActivityCancellationSignal(params.taskId)
if (signal?.aborted) {
@@ -279,7 +302,7 @@ export async function transcodeVideoActivity(
}
const tmpDir = path.dirname(params.filePath)
const outputFile = path.join(tmpDir, `${stem}-${res}.mp4`)
const outputFile = path.join(tmpDir, `${stem}-${suffix}.mp4`)
try {
let targetFps: number | string = params.originalFps || 30
@@ -307,6 +330,12 @@ export async function transcodeVideoActivity(
sourceVideoBitrate: params.sourceVideoBitrate,
threads: params.threads,
signal,
hdr: params.videoSpec.hdr,
sourceIsHdr: params.sourceIsHdr,
sourceHdrType: params.sourceHdrType,
sourceColorTransfer: params.sourceColorTransfer,
sourceColorPrimaries: params.sourceColorPrimaries,
sourceColorSpace: params.sourceColorSpace,
})
const stat = fs.statSync(outputFile)
@@ -339,7 +368,9 @@ export async function transcodeVideoActivity(
lowerMsg.includes('ffprobe') ||
lowerMsg.includes('spawn') ||
lowerMsg.includes('format') ||
lowerMsg.includes('no video stream found')
lowerMsg.includes('no video stream found') ||
lowerMsg.includes('zscale') ||
lowerMsg.includes('tonemap')
) {
throw ApplicationFailure.create({
message: `Video transcoding failed: ${message}`,
@@ -558,6 +589,11 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
posterFile,
params.mediaInfo.duration,
signal,
{
isHdr: params.mediaInfo.metadata?.isHdr,
hdrType: params.mediaInfo.metadata?.hdrType,
colorTransfer: params.mediaInfo.metadata?.colorTransfer,
},
)
}
@@ -604,7 +640,9 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
lowerMsg.includes('ffmpeg') ||
lowerMsg.includes('ffprobe') ||
lowerMsg.includes('spawn') ||
lowerMsg.includes('format')
lowerMsg.includes('format') ||
lowerMsg.includes('zscale') ||
lowerMsg.includes('tonemap')
) {
throw ApplicationFailure.create({
message: `Sprite/Poster generation failed: ${message}`,
@@ -857,6 +895,9 @@ export interface ExtractPosterActivityParams {
posterSpec: PrismaJson.PosterInfo
taskId?: string
signal?: AbortSignal
isHdr?: boolean
hdrType?: HdrType
colorTransfer?: string
}
export async function extractPosterActivity(
@@ -885,6 +926,17 @@ export async function extractPosterActivity(
const inputSource = await s3Service.resolveInput(bucket, params.assetKey)
const isRemote = inputSource.startsWith('http://') || inputSource.startsWith('https://')
let vf = 'scale=-2:300:force_original_aspect_ratio=decrease'
if (params.isHdr) {
const availableFilters = await transcodeService.getAvailableFilters()
const tonemap = buildSdrToneMapFilterChain({
hdrType: params.hdrType,
colorTransfer: params.colorTransfer,
availableFilters,
})
vf = `${tonemap},scale=-2:300:force_original_aspect_ratio=decrease`
}
const args = [
...(isRemote
? ['-reconnect', '1', '-reconnect_streamed', '1', '-reconnect_delay_max', '5']
@@ -896,7 +948,7 @@ export async function extractPosterActivity(
'-vframes',
'1',
'-vf',
'scale=-2:300:force_original_aspect_ratio=decrease',
vf,
'-c:v',
'libwebp',
'-q:v',
@@ -938,7 +990,9 @@ export async function extractPosterActivity(
lowerMsg.includes('enoent') ||
lowerMsg.includes('nosuchkey') ||
lowerMsg.includes('ffmpeg') ||
lowerMsg.includes('sharp')
lowerMsg.includes('sharp') ||
lowerMsg.includes('zscale') ||
lowerMsg.includes('tonemap')
) {
throw ApplicationFailure.create({
message: `Poster extraction failed: ${message}`,
@@ -405,6 +405,125 @@ describe('Watermark Activities', () => {
fs.rmSync(outFilePath, { force: true })
})
it('mirrors both SDR and HDR videoTranscodes preserving HDR flags and -hdr suffix', async () => {
const assetKey = 'files/hdr-wm/video.mp4'
const storageKey = await prisma.storageKey.create({ data: { key: assetKey } })
const asset = await prisma.asset.create({
data: {
name: 'video.mp4',
type: 'file',
status: 'processed',
storageKeyId: storageKey.id,
mediaType: 'video/mp4',
media: {
duration: 10,
filesize: 0,
frames: 300,
proxyType: 'video',
imageTranscodes: [],
videoPreview: { width: 1920, height: 1080 },
finishedAt: new Date().toISOString(),
original: {
key: assetKey,
filesizeInBytes: 0,
codec: '',
},
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
bitRate: 1000,
frameRate: 30,
totalFrames: 300,
startTimecode: '00:00:00:00',
hasAudio: true,
format: {},
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
},
videoTranscodes: [
{
key: 'files/hdr-wm/video-1080p.mp4',
resolution: '1080p',
width: 1920,
height: 1080,
hdr: false,
},
{
key: 'files/hdr-wm/video-1080p-hdr.mp4',
resolution: '1080p',
width: 1920,
height: 1080,
hdr: true,
},
],
} as PrismaJson.MediaInfo,
},
})
const config = await seedConfig()
vi.mocked(transcodeService.getVideoInfo).mockResolvedValue({
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
bitRate: 1000,
frameRate: 30,
totalFrames: 300,
startTimecode: '00:00:00:00',
hasAudio: true,
mimeType: 'video/mp4',
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
})
vi.mocked(s3Service.putObject).mockResolvedValue(undefined as never)
const sdrOut = path.join('/tmp', `video-watermark-${config.id}-1080p.mp4`)
const hdrOut = path.join('/tmp', `video-watermark-${config.id}-1080p-hdr.mp4`)
fs.writeFileSync(sdrOut, Buffer.from('fake sdr'))
fs.writeFileSync(hdrOut, Buffer.from('fake hdr'))
const media = await transcodeWatermarkMediaActivity({
assetId: asset.id,
watermarkConfigId: config.id,
})
expect(media.videoTranscodes).toHaveLength(2)
expect(media.videoTranscodes?.[0]).toEqual(
expect.objectContaining({
resolution: '1080p',
hdr: false,
key: expect.stringContaining(`video-watermark-${config.id}-1080p.mp4`),
}),
)
expect(media.videoTranscodes?.[1]).toEqual(
expect.objectContaining({
resolution: '1080p',
hdr: true,
key: expect.stringContaining(`video-watermark-${config.id}-1080p-hdr.mp4`),
}),
)
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
expect.objectContaining({
outputFile: sdrOut,
hdr: false,
sourceIsHdr: true,
}),
)
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
expect.objectContaining({
outputFile: hdrOut,
hdr: true,
sourceIsHdr: true,
}),
)
fs.rmSync(sdrOut, { force: true })
fs.rmSync(hdrOut, { force: true })
})
})
describe('completeWatermarkFileActivity', () => {
+28 -1
View File
@@ -181,6 +181,12 @@ export async function transcodeWatermarkMediaActivity(
let startTimecode = '00:00:00:00'
let hasAudio = false
let sourceVideoBitrate: number | undefined
let colorTransfer: string | undefined
let colorPrimaries: string | undefined
let colorSpace: string | undefined
let isHdr: boolean | undefined
let hdrType: PrismaJson.HdrType | undefined
let dvProfile: number | undefined
if (isVideo) {
const info = await transcodeService.getVideoInfo(rawFilePath)
@@ -194,6 +200,12 @@ export async function transcodeWatermarkMediaActivity(
startTimecode = info.startTimecode || '00:00:00:00'
hasAudio = info.hasAudio
sourceVideoBitrate = info.videoBitRate || info.bitRate
colorTransfer = info.colorTransfer
colorPrimaries = info.colorPrimaries
colorSpace = info.colorSpace
isHdr = info.isHdr
hdrType = info.hdrType
dvProfile = info.dvProfile
} else if (isImage) {
const info = await transcodeService.getImageInfo(rawFilePath)
originalWidth = info.originalWidth
@@ -258,6 +270,12 @@ export async function transcodeWatermarkMediaActivity(
totalFrames,
startTimecode,
hasAudio,
colorTransfer: colorTransfer ?? originalMedia?.metadata?.colorTransfer,
colorPrimaries: colorPrimaries ?? originalMedia?.metadata?.colorPrimaries,
colorSpace: colorSpace ?? originalMedia?.metadata?.colorSpace,
isHdr: isHdr ?? originalMedia?.metadata?.isHdr,
hdrType: hdrType ?? originalMedia?.metadata?.hdrType,
dvProfile: dvProfile ?? originalMedia?.metadata?.dvProfile,
format: {},
},
original: {
@@ -320,6 +338,8 @@ export async function transcodeWatermarkMediaActivity(
const targetWidth = vt.width || originalWidth
const targetHeight = vt.height || originalHeight
const resolution = vt.resolution || `${targetHeight}p`
const isVtHdr = Boolean(vt.hdr)
const suffix = isVtHdr ? `${resolution}-hdr` : resolution
const svgString = generateWatermarkSvg(config, targetWidth, targetHeight, blockImagesMap)
const overlayPngBuffer = await transcodeService.renderSvgToPng(svgString)
@@ -327,7 +347,7 @@ export async function transcodeWatermarkMediaActivity(
const overlayPngPath = path.join(tmpDir, `watermarkOverlay-${i}.png`)
fs.writeFileSync(overlayPngPath, overlayPngBuffer)
const outFileName = `${stem}-watermark-${params.watermarkConfigId}-${resolution}.mp4`
const outFileName = `${stem}-watermark-${params.watermarkConfigId}-${suffix}.mp4`
const outFilePath = path.join(tmpDir, outFileName)
await transcodeService.transcodeVideo({
@@ -340,6 +360,12 @@ export async function transcodeWatermarkMediaActivity(
hardwareAcceleration,
sourceVideoBitrate,
threads,
hdr: isVtHdr,
sourceIsHdr: isHdr ?? originalMedia?.metadata?.isHdr,
sourceHdrType: hdrType ?? originalMedia?.metadata?.hdrType,
sourceColorTransfer: colorTransfer ?? originalMedia?.metadata?.colorTransfer,
sourceColorPrimaries: colorPrimaries ?? originalMedia?.metadata?.colorPrimaries,
sourceColorSpace: colorSpace ?? originalMedia?.metadata?.colorSpace,
})
const stat = fs.statSync(outFilePath)
@@ -359,6 +385,7 @@ export async function transcodeWatermarkMediaActivity(
width: targetWidth,
height: targetHeight,
resolution,
hdr: isVtHdr,
})
}
mediaInfo.filesize = totalSize
@@ -168,4 +168,58 @@ describe('takeVideoScreenshotsWorkflow', () => {
annotations: [],
})
})
it('should prioritize SDR proxy over higher-resolution HDR proxy to avoid washed-out annotations', async () => {
const task: WorkflowTask = {
id: 'task-screenshot-sdr-prioritized',
assetId: 'asset-video-hdr',
type: WorkflowTaskType.transcode_screenshot,
status: WorkflowTaskStatus.pending,
sessionId: null,
output: null,
payload: {
projectId: 'proj-1',
screenshot: {
start: 2.0,
end: 2.0,
count: 1,
commentTimestamp: 2.0,
annotations: [],
},
},
createdAt: new Date(),
updatedAt: new Date(),
heartbeat: null,
teamId: 'team-1',
projectId: 'proj-1',
uid: 'task-uid',
model: null,
inputTokens: 0,
outputTokens: 0,
}
mockActivities.getAssetActivity.mockResolvedValue({
id: 'asset-video-hdr',
storageKey: { key: 'raw-hdr.mp4' },
mediaType: 'video/mp4',
media: {
videoTranscodes: [
{ key: 'proxy-1080p-hdr.mp4', height: 1080, width: 1920, hdr: true },
{ key: 'proxy-720p.mp4', height: 720, width: 1280, hdr: false },
],
},
})
mockActivities.takeScreenshotsActivity.mockResolvedValue([
{ key: 'files/asset-video-hdr/screenshots/shot1.webp', timestamp: 2.0 },
])
await takeVideoScreenshotsWorkflow(task)
expect(mockActivities.takeScreenshotsActivity).toHaveBeenCalledWith(
expect.objectContaining({
assetKey: 'proxy-720p.mp4',
}),
)
})
})
@@ -23,7 +23,12 @@ export async function takeVideoScreenshotsWorkflow(task: WorkflowTask): Promise<
if (mediaInfo.videoTranscodes && mediaInfo.videoTranscodes.length > 0) {
const sorted = [...mediaInfo.videoTranscodes]
.filter((t) => t.key)
.sort((a, b) => (b.height || 0) - (a.height || 0))
.sort((a, b) => {
// Prioritize SDR over HDR to avoid washed out screenshots
if (!a.hdr && b.hdr) return -1
if (a.hdr && !b.hdr) return 1
return (b.height || 0) - (a.height || 0)
})
if (sorted.length > 0 && sorted[0].key) {
targetKey = sorted[0].key
}
@@ -497,4 +497,209 @@ describe('transcodeVideoWorkflow', () => {
mockActivities.updateAssetMediaActivity.mock.invocationCallOrder[spriteCommitIndex],
).toBeLessThan(firstProxyOrder)
})
it('should transcode only HDR proxies and HDR 180p preview when source is HDR', async () => {
const task: WorkflowTask = {
id: 'task-hdr',
assetId: 'asset-hdr',
type: WorkflowTaskType.transcode_video,
status: WorkflowTaskStatus.pending,
sessionId: null,
output: null,
payload: {
projectId: 'proj-1',
transcode: {
videoStrategy: 'best_match',
poster: true,
},
},
createdAt: new Date(),
updatedAt: new Date(),
heartbeat: null,
teamId: 'team-1',
projectId: 'proj-1',
uid: 'task-uid-hdr',
model: null,
inputTokens: 0,
outputTokens: 0,
}
mockActivities.getAssetActivity.mockResolvedValue({
id: 'asset-hdr',
storageKey: { key: 'hdr-video.mp4' },
mediaType: 'video/mp4',
})
mockActivities.getMediaInfoActivity.mockResolvedValue({
proxyType: 'video',
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
startTimecode: '00:00:00:00',
bitRate: 1000,
videoBitRate: 850000,
hasAudio: false,
format: {},
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
colorPrimaries: 'bt2020',
colorSpace: 'bt2020nc',
},
videoTranscodes: [],
imageTranscodes: [],
})
mockActivities.transcodeVideoActivity.mockImplementation(async (params) => {
return {
key: `files/asset-hdr/video-${params.videoSpec.resolution}${params.videoSpec.hdr ? '-hdr' : ''}.mp4`,
width: params.videoSpec.width,
height: params.videoSpec.height,
resolution: params.videoSpec.resolution,
hdr: params.videoSpec.hdr,
}
})
await transcodeVideoWorkflow(task)
// Poster extraction must use SDR tone mapping
expect(mockActivities.extractPosterActivity).toHaveBeenCalledWith(
expect.objectContaining({
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
}),
)
// 180p preview must be generated as HDR (hdr: true)
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
expect.objectContaining({
videoSpec: expect.objectContaining({
resolution: '180p',
hdr: true,
}),
}),
)
// Main resolution (1080p) must be called as HDR (hdr: true)
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
expect.objectContaining({
videoSpec: expect.objectContaining({
resolution: '1080p',
hdr: true,
}),
}),
)
// No calls should have been made with hdr: false for HDR source
const calls = mockActivities.transcodeVideoActivity.mock.calls
const sdrCalls = calls.filter(
(c: unknown[]) => (c[0] as { videoSpec: { hdr?: boolean } }).videoSpec.hdr === false,
)
expect(sdrCalls).toHaveLength(0)
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
taskId: 'task-hdr',
status: WorkflowTaskStatus.completed,
})
})
it('should transcode only SDR proxy and SDR 180p preview when source is SDR', async () => {
const task: WorkflowTask = {
id: 'task-sdr-source',
assetId: 'asset-sdr-source',
type: WorkflowTaskType.transcode_video,
status: WorkflowTaskStatus.pending,
sessionId: null,
output: null,
payload: {
projectId: 'proj-1',
transcode: {
videoStrategy: 'best_match',
poster: true,
},
},
createdAt: new Date(),
updatedAt: new Date(),
heartbeat: null,
teamId: 'team-1',
projectId: 'proj-1',
uid: 'task-uid-sdr-source',
model: null,
inputTokens: 0,
outputTokens: 0,
}
mockActivities.getAssetActivity.mockResolvedValue({
id: 'asset-sdr-source',
storageKey: { key: 'sdr-video.mp4' },
mediaType: 'video/mp4',
})
mockActivities.getMediaInfoActivity.mockResolvedValue({
proxyType: 'video',
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
startTimecode: '00:00:00:00',
bitRate: 1000,
videoBitRate: 850000,
hasAudio: false,
format: {},
isHdr: false,
},
videoTranscodes: [],
imageTranscodes: [],
})
mockActivities.transcodeVideoActivity.mockImplementation(async (params) => {
return {
key: `files/asset-sdr-source/video-${params.videoSpec.resolution}.mp4`,
width: params.videoSpec.width,
height: params.videoSpec.height,
resolution: params.videoSpec.resolution,
hdr: params.videoSpec.hdr,
}
})
await transcodeVideoWorkflow(task)
// 180p preview must be generated as SDR (hdr: false)
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
expect.objectContaining({
videoSpec: expect.objectContaining({
resolution: '180p',
hdr: false,
}),
}),
)
// Main resolution (1080p) must be generated as SDR (hdr: false)
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
expect.objectContaining({
videoSpec: expect.objectContaining({
resolution: '1080p',
hdr: false,
}),
}),
)
// No calls should have been made with hdr: true for SDR source
const calls = mockActivities.transcodeVideoActivity.mock.calls
const hdrCalls = calls.filter(
(c: unknown[]) => (c[0] as { videoSpec: { hdr?: boolean } }).videoSpec.hdr === true,
)
expect(hdrCalls).toHaveLength(0)
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
taskId: 'task-sdr-source',
status: WorkflowTaskStatus.completed,
})
})
})
@@ -69,6 +69,9 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
assetKey: key,
posterSpec,
taskId: task.id,
isHdr: mediaInfo.metadata?.isHdr,
hdrType: mediaInfo.metadata?.hdrType,
colorTransfer: mediaInfo.metadata?.colorTransfer,
})
mediaInfo.poster = posterResult.poster
await executeActivity(workerQueue, updateAssetMediaActivity, {
@@ -129,10 +132,42 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
metadata.originalHeight,
)
const isHdr = Boolean(metadata.isHdr)
if (res === '180p') {
const videoSpec: PrismaJson.VideoTranscode = {
resolution: res,
width,
height,
hdr: isHdr,
}
const videoTranscode = await executeActivity(workerQueue, transcodeVideoActivity, {
taskId: task.id,
assetKey: key,
filePath,
videoSpec,
duration: metadata.duration,
originalFps: metadata.frameRate,
hardwareAcceleration: spec.hardwareAcceleration,
sourceVideoBitrate: metadata.videoBitRate || metadata.bitRate,
threads: spec.threads,
sourceIsHdr: metadata.isHdr,
sourceHdrType: metadata.hdrType,
sourceColorTransfer: metadata.colorTransfer,
sourceColorPrimaries: metadata.colorPrimaries,
sourceColorSpace: metadata.colorSpace,
})
mediaInfo.videoPreview = videoTranscode
continue
}
const videoSpec: PrismaJson.VideoTranscode = {
resolution: res,
width,
height,
hdr: isHdr,
}
const videoTranscode = await executeActivity(workerQueue, transcodeVideoActivity, {
@@ -145,13 +180,14 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
hardwareAcceleration: spec.hardwareAcceleration,
sourceVideoBitrate: metadata.videoBitRate || metadata.bitRate,
threads: spec.threads,
sourceIsHdr: metadata.isHdr,
sourceHdrType: metadata.hdrType,
sourceColorTransfer: metadata.colorTransfer,
sourceColorPrimaries: metadata.colorPrimaries,
sourceColorSpace: metadata.colorSpace,
})
if (res === '180p') {
mediaInfo.videoPreview = videoTranscode
} else {
mediaInfo.videoTranscodes.push(videoTranscode)
}
mediaInfo.videoTranscodes.push(videoTranscode)
}
}
+4 -2
View File
@@ -84,6 +84,7 @@ interface BreadcrumbNavProps {
key: string
width: number
height: number
hdr?: boolean
}>
}
versions?: Array<{
@@ -294,13 +295,14 @@ export function BreadcrumbNav({
else if (longSide >= 960) resolution = '540p'
else if (longSide >= 640) resolution = '360p'
else if (longSide >= 320) resolution = '180p'
const label = t.hdr ? `${resolution} (HDR)` : resolution
return (
<DropdownMenuItem
key={resolution}
key={t.key || `${resolution}-${t.hdr ? 'hdr' : 'sdr'}`}
onClick={() => handleDownload(t.key)}
className="flex items-center justify-between"
>
<span>{resolution}</span>
<span>{label}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
)
@@ -19,7 +19,7 @@ interface CompareControlBarProps {
onVolumeChange: (volume: number) => void
onToggleMute: () => void
onChangePlaybackRate: (rate: number) => void
onChangeResolution: (resolution: string) => void
onChangeResolution: (resolution: string, hdr?: boolean) => void
onZoomIn: () => void
onZoomOut: () => void
onFit: () => void
@@ -65,6 +65,7 @@ export function CompareControlBar({
isFullScreen,
showFrames: false,
currentResolution: v.currentResolution,
isCurrentHdr: v.isCurrentHdr,
}
// The active-side asset carries the metadata used for timecode display and
@@ -88,7 +89,7 @@ export function CompareControlBar({
toggleMute={onToggleMute}
handleVolumeChange={onVolumeChange}
changePlaybackRate={onChangePlaybackRate}
changeResolution={(res: DisplayTranscode) => onChangeResolution(res.resolution)}
changeResolution={(res: DisplayTranscode) => onChangeResolution(res.resolution, res.hdr)}
handleDownload={(key?: string) => onDownload(key)}
toggleFullScreen={onToggleFullScreen}
onZoomChange={(nz: number) => (nz >= activeState.zoom ? onZoomIn() : onZoomOut())}
@@ -213,7 +213,7 @@ export function CompareViewer({
)
const handleChangeResolution = useCallback(
(resolution: string) => getActive()?.changeResolution(resolution),
(resolution: string, hdr?: boolean) => getActive()?.changeResolution(resolution, hdr),
[getActive],
)
+2 -1
View File
@@ -23,6 +23,7 @@ export interface PaneReportedState {
playbackRate: number
isLooping: boolean
currentResolution: string
isCurrentHdr?: boolean
resolutions: DisplayTranscode[]
buffered: number
}
@@ -45,7 +46,7 @@ export interface ComparePaneHandle {
setVolume: (volume: number) => void
setPlaybackRate: (rate: number) => void
toggleLoop: () => void
changeResolution: (resolution: string) => void
changeResolution: (resolution: string, hdr?: boolean) => void
// Zoom / pan (image + video)
zoomBy: (factor: number) => void
fit: () => void
+37 -52
View File
@@ -19,7 +19,6 @@ interface DrawingCanvasProps {
imageUrl?: string
/** A live canvas to draw instead of an image URL (e.g. a PDF.js page render). */
canvasElement?: HTMLCanvasElement | null
videoElement?: HTMLVideoElement
annotations: Annotation[]
scale: number
offset: { x: number; y: number }
@@ -40,7 +39,6 @@ const DrawingCanvas = ({
mediaDimensions,
imageUrl,
canvasElement,
videoElement,
annotations,
scale,
offset,
@@ -53,7 +51,7 @@ const DrawingCanvas = ({
onAddAnnotation,
}: DrawingCanvasProps) => {
const [loadedImage] = useImage(imageUrl || '', 'anonymous')
const imageRef = useRef<Konva.Image>(null)
const mediaGroupRef = useRef<Konva.Group>(null)
const isDragging = useRef(false)
const lastPos = useRef({ x: 0, y: 0 })
const startPointRef = useRef<{ x: number; y: number } | null>(null)
@@ -66,27 +64,11 @@ const DrawingCanvas = ({
// Force a redraw whenever the live canvas source is swapped, so the layer
// picks up the new page raster (Konva redraws the source each batchDraw).
useEffect(() => {
if (canvasElement && imageRef.current) {
imageRef.current.getLayer()?.batchDraw()
if (canvasElement && mediaGroupRef.current) {
mediaGroupRef.current.getLayer()?.batchDraw()
}
}, [canvasElement])
// Handle Video Redraw
useEffect(() => {
if (videoElement && imageRef.current) {
const layer = imageRef.current.getLayer()
if (!layer) return
const anim = new Konva.Animation(() => {
// Force redraw to update video frame
}, layer)
anim.start()
return () => {
anim.stop()
}
}
}, [videoElement])
// -- Helpers --
const getRelativePointerPosition = (
node: Konva.Node,
@@ -217,7 +199,7 @@ const DrawingCanvas = ({
const handleGlobalMove = (e: MouseEvent | TouchEvent) => {
if (!isDragging.current) return
const stage = imageRef.current?.getStage()
const stage = mediaGroupRef.current?.getStage()
if (!stage) return
const container = stage.container()
const rect = container.getBoundingClientRect()
@@ -255,11 +237,11 @@ const DrawingCanvas = ({
if (activeDrawing) {
if (tool === 'select') return
const pos = getRelativePointerPosition(imageRef.current!, true, stagePos)
const pos = getRelativePointerPosition(mediaGroupRef.current!, true, stagePos)
if (!pos || !startPointRef.current) return
const start = startPointRef.current
const layer = imageRef.current?.getLayer()
const layer = mediaGroupRef.current?.getLayer()
if (tool === 'freehand' && currentLineRef.current) {
const newPoints = currentLineRef.current.points().concat([pos.x, pos.y])
@@ -317,8 +299,8 @@ const DrawingCanvas = ({
const stage = e.target.getStage()
if (!stage) return
// Use imageRef to get coordinates relative to the image (handling zoom/pan)
const pos = getRelativePointerPosition(imageRef.current!)
// Use mediaGroupRef to get coordinates relative to the media (handling zoom/pan)
const pos = getRelativePointerPosition(mediaGroupRef.current!)
if (!pos) return
// Only start drawing if within media bounds
@@ -334,7 +316,7 @@ const DrawingCanvas = ({
isDragging.current = true
startPointRef.current = pos
const layer = imageRef.current?.getLayer()
const layer = mediaGroupRef.current?.getLayer()
if (!layer) return
if (currentTool === 'freehand' && currentLineRef.current) {
@@ -474,32 +456,35 @@ const DrawingCanvas = ({
onTouchStart={handleMouseDown}
>
<Layer>
<KonvaImage
ref={imageRef}
image={videoElement || canvasElement || loadedImage}
width={mediaDimensions.width}
height={mediaDimensions.height}
/>
{annotations.map(renderAnnotation)}
<Group ref={mediaGroupRef} width={mediaDimensions.width} height={mediaDimensions.height}>
{(canvasElement || loadedImage) && (
<KonvaImage
image={canvasElement || loadedImage}
width={mediaDimensions.width}
height={mediaDimensions.height}
/>
)}
{annotations.map(renderAnnotation)}
{/* Draft Shapes */}
<Group listening={false}>
<Line
ref={currentLineRef}
strokeWidth={2.6 / scale}
lineCap="round"
lineJoin="round"
visible={false}
/>
<Rect ref={currentRectRef} strokeWidth={2.6 / scale} visible={false} />
<Arrow
ref={currentArrowRef}
points={[]}
strokeWidth={2.6 / scale}
pointerLength={10 / scale}
pointerWidth={10 / scale}
visible={false}
/>
{/* Draft Shapes */}
<Group listening={false}>
<Line
ref={currentLineRef}
strokeWidth={2.6 / scale}
lineCap="round"
lineJoin="round"
visible={false}
/>
<Rect ref={currentRectRef} strokeWidth={2.6 / scale} visible={false} />
<Arrow
ref={currentArrowRef}
points={[]}
strokeWidth={2.6 / scale}
pointerLength={10 / scale}
pointerWidth={10 / scale}
visible={false}
/>
</Group>
</Group>
</Layer>
</Stage>
@@ -145,6 +145,7 @@ export function MobileFileDetail({
key: t.key,
width: t.width,
height: t.height,
hdr: t.hdr,
})),
}
}, [file.media])
@@ -46,6 +46,7 @@ export interface MobileFileHeaderProps {
key: string
width: number
height: number
hdr?: boolean
}>
}
canEdit?: boolean
@@ -245,13 +246,14 @@ export function MobileFileHeader({
else if (longSide >= 960) resolution = '540p'
else if (longSide >= 640) resolution = '360p'
else if (longSide >= 320) resolution = '180p'
const label = t.hdr ? `${resolution} (HDR)` : resolution
return (
<DropdownMenuItem
key={resolution}
key={t.key || `${resolution}-${t.hdr ? 'hdr' : 'sdr'}`}
onClick={() => handleDownload(t.key)}
className="flex items-center justify-between text-xs cursor-pointer"
>
<span>{resolution}</span>
<span>{label}</span>
<span className="text-[10px] text-muted-foreground">MP4</span>
</DropdownMenuItem>
)
@@ -440,6 +440,7 @@ export function PublicShareManager({
key: t.key,
width: t.width,
height: t.height,
hdr: t.hdr,
})),
}
: undefined,
@@ -45,6 +45,28 @@ function computeResolutions(file: AssetInfo): DisplayTranscode[] {
})
}
function getInitialResolution(resolutions: DisplayTranscode[]): DisplayTranscode | null {
if (resolutions.length === 0) return null
if (typeof window === 'undefined') return resolutions[0]
const prefersHdr =
typeof window.matchMedia === 'function' && window.matchMedia('(dynamic-range: high)').matches
const hasHdr = resolutions.some((r) => r.hdr)
const hasSdr = resolutions.some((r) => !r.hdr)
let candidates = resolutions
if (prefersHdr && hasHdr) {
candidates = resolutions.filter((r) => r.hdr)
} else if (!prefersHdr && hasSdr) {
candidates = resolutions.filter((r) => !r.hdr)
}
const screenWidth = window.innerWidth * (window.devicePixelRatio || 1)
const sorted = [...candidates].sort((a, b) => (a.width ?? 0) - (b.width ?? 0))
const bestFit = sorted.find((r) => (r.width ?? 0) >= screenWidth)
return bestFit || sorted[sorted.length - 1]
}
export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPaneProps>(
function CompareVideoPane(
{
@@ -66,7 +88,6 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
const videoContainerRef = useRef<HTMLDivElement>(null)
const containerRef = useRef<HTMLDivElement>(null)
const videoRef = useRef<HTMLVideoElement | null>(null)
const [videoHtmlEl, setVideoHtmlEl] = useState<HTMLVideoElement | undefined>(undefined)
const {
isDrawing,
@@ -82,6 +103,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
const [pan, setPan] = useState<{ x: number; y: number } | null>(null)
const [isPlaying, setIsPlaying] = useState(false)
const [hasStartedPlaying, setHasStartedPlaying] = useState(false)
const [isLooping, setIsLooping] = useState(false)
const [playbackRate, setPlaybackRate] = useState(1)
const [buffered, setBuffered] = useState(0)
@@ -96,8 +118,9 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
const resolutions = computeResolutions(file)
const initialRes = resolutions[0]
const initialRes = getInitialResolution(resolutions)
const [currentResolution, setCurrentResolution] = useState(initialRes?.resolution ?? '')
const [isCurrentHdr, setIsCurrentHdr] = useState(initialRes?.hdr)
const currentSrcRef = useRef(initialRes?.url)
const isAudio = file.proxyType === 'audio'
@@ -137,8 +160,11 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
// if the parent renders this pane without a per-asset `key`. Runs before the
// video.js init effect below (declaration order) so the ref is fresh.
useEffect(() => {
setCurrentResolution(initialRes?.resolution ?? '')
currentSrcRef.current = initialRes?.url
const res = getInitialResolution(resolutions)
setCurrentResolution(res?.resolution ?? '')
setIsCurrentHdr(res?.hdr)
currentSrcRef.current = res?.url
setHasStartedPlaying(false)
}, [file.id])
// Initialize video.js
@@ -146,7 +172,6 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
if (!videoContainerRef.current) return
const videoElement = document.createElement('video-js')
videoElement.classList.add('vjs-big-play-centered', '!h-full', '!w-full')
videoElement.style.opacity = '0'
videoElement.style.pointerEvents = 'none'
videoContainerRef.current.appendChild(videoElement)
@@ -160,13 +185,11 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
const htmlVid = videoElement.querySelector('video')
if (htmlVid) {
setVideoHtmlEl(htmlVid)
videoRef.current = htmlVid
} else {
player.ready(() => {
const techEl = player.tech({ iWillNotUseThisInPlugins: true })?.el() as HTMLVideoElement
if (techEl) {
setVideoHtmlEl(techEl)
videoRef.current = techEl
}
})
@@ -174,17 +197,20 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
player.on('play', () => {
setIsPlaying(true)
setHasStartedPlaying(true)
onPlay?.()
})
player.on('pause', () => setIsPlaying(false))
player.on('ended', () => setIsPlaying(false))
player.on('loadedmetadata', () => setIsPlayerReady(true))
player.on('loadstart', () => setIsPlayerReady(false))
player.on('timeupdate', () => {
const playerDuration = player.duration() || containerDuration || 0
const bufferedEnd = player.bufferedEnd()
if (playerDuration > 0) setBuffered((bufferedEnd / playerDuration) * 100)
setBuffered(player.bufferedPercent())
})
player.on('loadedmetadata', () => {
setIsPlayerReady(true)
})
player.on('loadstart', () => setIsPlayerReady(false))
player.on('volumechange', () => {
setPlayerVolume(player.volume() || 0)
setPlayerMuted(player.muted() || false)
@@ -223,6 +249,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
playbackRate,
isLooping,
currentResolution,
isCurrentHdr,
resolutions,
buffered,
},
@@ -239,6 +266,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
playbackRate,
isLooping,
currentResolution,
isCurrentHdr,
buffered,
])
@@ -294,14 +322,20 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
)
const changeResolution = useCallback(
(resolution: string) => {
(resolution: string, hdr?: boolean) => {
const player = playerRef.current
if (!player) return
const target = resolutions.find((r) => r.resolution === resolution)
const target =
hdr !== undefined
? resolutions.find(
(r) => r.resolution === resolution && Boolean(r.hdr) === Boolean(hdr),
)
: resolutions.find((r) => r.resolution === resolution)
if (!target) return
const wasPlaying = !player.paused()
const currentT = player.currentTime()
setCurrentResolution(resolution)
setIsCurrentHdr(target.hdr)
currentSrcRef.current = target.url
player.src({ type: 'video/mp4', src: target.url })
player.one('loadedmetadata', () => {
@@ -334,12 +368,19 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
player.pause()
}
},
seekToFrame: (frame) => seekToFrame(clampFrame(frame)),
seekToFrame: (frame) => {
setHasStartedPlaying(true)
return seekToFrame(clampFrame(frame))
},
seekToSecond: (second) => {
setHasStartedPlaying(true)
const frame = Math.floor(second * frameRate + 0.45)
seekToFrame(clampFrame(frame))
},
stepFrame: (delta) => seekToFrame(clampFrame(currentFrameRef.current + delta)),
stepFrame: (delta) => {
setHasStartedPlaying(true)
return seekToFrame(clampFrame(currentFrameRef.current + delta))
},
setMuted: (m) => playerRef.current?.muted(m),
setVolume: (v) => {
const player = playerRef.current
@@ -420,7 +461,28 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
onClick={handleAreaClick}
data-testid="compare-video-area"
>
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
{/* Native Video Layer (Hardware-accelerated, full HDR EDR) */}
{!isAudio && (
<div
className="absolute pointer-events-none"
style={{
left: 0,
top: 0,
width: vidW,
height: vidH,
transform: `translate(${panX}px, ${panY}px) scale(${scale})`,
transformOrigin: '0 0',
}}
>
<div
ref={videoContainerRef}
className="w-full h-full [&_.video-js]:!w-full [&_.video-js]:!h-full [&_video]:!w-full [&_video]:!h-full [&_video]:!block [&_video]:!object-contain"
/>
</div>
)}
{isAudio && (
<div ref={videoContainerRef} className="absolute inset-0 pointer-events-none opacity-0" />
)}
{isAudio ? (
<div className="flex flex-col items-center justify-center text-muted-foreground w-full h-full pointer-events-none select-none">
@@ -432,13 +494,11 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
/>
</div>
) : (
videoHtmlEl &&
containerSize.width > 0 && (
<DrawingCanvas
width={containerSize.width}
height={containerSize.height}
mediaDimensions={{ width: vidW, height: vidH }}
videoElement={videoHtmlEl}
annotations={displayAnnotations}
scale={scale}
offset={{ x: panX, y: panY }}
@@ -452,8 +512,8 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
)
)}
{!isPlaying && !isDrawing && (
<div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-black/20">
{!hasStartedPlaying && !isDrawing && (
<div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-black/20 transition-opacity duration-200">
<div className="flex h-16 w-16 items-center justify-center rounded-full border-2 border-white/30 bg-white/10 backdrop-blur-sm">
<Play className="ml-1 h-8 w-8 fill-white text-white" />
</div>
@@ -93,4 +93,92 @@ describe('MobileVideoControlBar', () => {
fireEvent.click(fsBtn)
expect(toggleFullScreen).toHaveBeenCalledTimes(1)
})
it('renders HDR label on settings button when playing HDR video', () => {
render(
<MobileVideoControlBar
state={{
...defaultState,
currentResolution: '1080p',
isCurrentHdr: true,
}}
zoom={1}
isControlsVisible={true}
buffered={50}
data={mockData}
resolutions={[
{
key: '1080-hdr.mp4',
width: 1920,
height: 1080,
resolution: '1080p',
hdr: true,
} as unknown as DisplayTranscode,
]}
togglePlay={vi.fn()}
toggleLoop={vi.fn()}
toggleMute={vi.fn()}
handleVolumeChange={vi.fn()}
changePlaybackRate={vi.fn()}
changeResolution={vi.fn()}
handleDownload={vi.fn()}
toggleFullScreen={vi.fn()}
onZoomChange={vi.fn()}
onZoomReset={vi.fn()}
frameRate={25}
totalFrames={2500}
currentFrame={250}
seekToFrame={vi.fn()}
/>,
)
const settingsBtn = screen.getByLabelText(/Settings/i)
expect(settingsBtn).toBeDefined()
expect(settingsBtn.textContent).toContain('1080p')
expect(settingsBtn.textContent).toContain('HDR')
})
it('does not render HDR label on settings button when playing SDR video', () => {
render(
<MobileVideoControlBar
state={{
...defaultState,
currentResolution: '1080p',
isCurrentHdr: false,
}}
zoom={1}
isControlsVisible={true}
buffered={50}
data={mockData}
resolutions={[
{
key: '1080.mp4',
width: 1920,
height: 1080,
resolution: '1080p',
hdr: false,
} as unknown as DisplayTranscode,
]}
togglePlay={vi.fn()}
toggleLoop={vi.fn()}
toggleMute={vi.fn()}
handleVolumeChange={vi.fn()}
changePlaybackRate={vi.fn()}
changeResolution={vi.fn()}
handleDownload={vi.fn()}
toggleFullScreen={vi.fn()}
onZoomChange={vi.fn()}
onZoomReset={vi.fn()}
frameRate={25}
totalFrames={2500}
currentFrame={250}
seekToFrame={vi.fn()}
/>,
)
const settingsBtn = screen.getByLabelText(/Settings/i)
expect(settingsBtn).toBeDefined()
expect(settingsBtn.textContent).toContain('1080p')
expect(settingsBtn.textContent).not.toContain('HDR')
})
})
@@ -186,10 +186,19 @@ export const MobileVideoControlBar: React.FC<ControlBarProps> = ({
aria-label={m.settings()}
>
<Settings className="h-3.5 w-3.5" />
<span className="text-[11px]">
{!isAudio && state.currentResolution
? state.currentResolution
: `${state.playbackRate}x`}
<span className="flex items-center gap-1 text-[11px]">
<span>
{!isAudio && state.currentResolution
? state.currentResolution === 'Original'
? m.original()
: state.currentResolution
: `${state.playbackRate}x`}
</span>
{!isAudio && state.isCurrentHdr && (
<span className="px-1 py-0.2 rounded text-[9px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
{m.hdr()}
</span>
)}
</span>
</button>
</DropdownMenuTrigger>
@@ -199,23 +208,36 @@ export const MobileVideoControlBar: React.FC<ControlBarProps> = ({
<DropdownMenuLabel className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">
{m.quality()}
</DropdownMenuLabel>
{resolutions.map((res) => (
<DropdownMenuItem
key={res.resolution}
onClick={() => changeResolution(res)}
className={cn(
'flex w-full items-center justify-between text-xs cursor-pointer',
state.currentResolution === res.resolution
? 'text-primary font-medium'
: 'text-foreground',
)}
>
<span>{res.resolution === 'Original' ? m.original() : res.resolution}</span>
<span className="text-[10px] text-muted-foreground">
{res.width}x{res.height}
</span>
</DropdownMenuItem>
))}
{resolutions.map((res) => {
const itemKey = `${res.resolution}-${res.hdr ? 'hdr' : 'sdr'}`
const isSelected =
state.currentResolution === res.resolution &&
Boolean(state.isCurrentHdr) === Boolean(res.hdr)
return (
<DropdownMenuItem
key={itemKey}
onClick={() => changeResolution(res)}
className={cn(
'flex w-full items-center justify-between text-xs cursor-pointer',
isSelected ? 'text-primary font-medium' : 'text-foreground',
)}
>
<div className="flex items-center gap-1.5">
<span>
{res.resolution === 'Original' ? m.original() : res.resolution}
</span>
{res.hdr && (
<span className="px-1 py-0.2 rounded text-[9px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
{m.hdr()}
</span>
)}
</div>
<span className="text-[10px] text-muted-foreground">
{res.width}x{res.height}
</span>
</DropdownMenuItem>
)
})}
<DropdownMenuSeparator />
</>
)}
@@ -0,0 +1,110 @@
// @vitest-environment happy-dom
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import React from 'react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { VideoControlBar } from './video-control-bar'
import type { AssetInfo } from '@shumai/dtos'
import type { DisplayTranscode, PlayerState } from './video-control-bar'
describe('VideoControlBar', () => {
afterEach(() => {
cleanup()
})
const mockData: AssetInfo = {
id: 'video-1',
name: 'sample.mp4',
proxyType: 'video',
media: {
original: { key: 'files/sample.mp4' },
metadata: {
duration: 100,
frameRate: 25,
},
},
} as AssetInfo
const defaultState: PlayerState = {
isPlaying: false,
progress: 10,
currentTime: 10,
duration: 100,
volume: 1,
isMuted: false,
isLooping: false,
playbackRate: 1,
isFullScreen: false,
showFrames: false,
currentResolution: '1080p',
isCurrentHdr: false,
}
const resolutions: DisplayTranscode[] = [
{
key: '1080.mp4',
width: 1920,
height: 1080,
resolution: '1080p',
hdr: false,
} as unknown as DisplayTranscode,
{
key: '1080-hdr.mp4',
width: 1920,
height: 1080,
resolution: '1080p',
hdr: true,
} as unknown as DisplayTranscode,
]
it('renders download menu with HDR badge on HDR download items', async () => {
const handleDownload = vi.fn()
render(
<VideoControlBar
state={defaultState}
zoom={1}
isControlsVisible={true}
buffered={50}
data={mockData}
resolutions={resolutions}
togglePlay={vi.fn()}
toggleLoop={vi.fn()}
toggleMute={vi.fn()}
handleVolumeChange={vi.fn()}
changePlaybackRate={vi.fn()}
changeResolution={vi.fn()}
handleDownload={handleDownload}
toggleFullScreen={vi.fn()}
onZoomChange={vi.fn()}
onZoomReset={vi.fn()}
frameRate={25}
totalFrames={2500}
currentFrame={250}
seekToFrame={vi.fn()}
allowDownload={true}
/>,
)
const downloadTrigger = screen.getByTitle(/Download/i)
expect(downloadTrigger).toBeDefined()
fireEvent.pointerDown(downloadTrigger, { button: 0, ctrlKey: false })
const menuItems = await screen.findAllByRole('menuitem')
// We expect: 1080p SDR, 1080p HDR, and Original
expect(menuItems.length).toBe(3)
const sdrItem = menuItems.find(
(item) => item.textContent?.includes('1080p') && !item.textContent?.includes('HDR'),
)
const hdrItem = menuItems.find(
(item) => item.textContent?.includes('1080p') && item.textContent?.includes('HDR'),
)
expect(sdrItem).toBeDefined()
expect(hdrItem).toBeDefined()
// Clicking HDR item triggers download with HDR key
fireEvent.click(hdrItem!)
expect(handleDownload).toHaveBeenCalledWith('1080-hdr.mp4')
})
})
@@ -43,6 +43,7 @@ export interface PlayerState {
showFrames: boolean // Toggle between time (02:30) and frames (1234)
currentResolution: string // 'Original' or '720p', '480p' etc.
currentSrc?: string
isCurrentHdr?: boolean
}
export type DisplayTranscode = VideoTranscode & { resolution: string }
@@ -317,35 +318,53 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
{!isAudio && resolutions.length > 0 && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button className="flex items-center gap-1 rounded border border-border px-2 py-0.5 text-sm font-semibold hover:bg-muted transition-colors">
<button className="flex items-center gap-1.5 rounded border border-border px-2 py-0.5 text-sm font-semibold hover:bg-muted transition-colors">
<Settings className="h-3.5 w-3.5" />
<span>
{state.currentResolution === 'Original'
? m.original()
: state.currentResolution}
<span className="flex items-center gap-1">
<span>
{state.currentResolution === 'Original'
? m.original()
: state.currentResolution}
</span>
{state.isCurrentHdr && (
<span className="px-1 py-0.2 rounded text-[10px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
{m.hdr()}
</span>
)}
</span>
</button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>{m.quality()}</DropdownMenuLabel>
{resolutions.map((res) => (
<DropdownMenuItem
key={res.resolution}
onClick={() => changeResolution(res)}
className={cn(
'flex w-full items-center justify-between',
state.currentResolution === res.resolution
? 'text-primary font-medium'
: 'text-foreground',
)}
>
<span>{res.resolution === 'Original' ? m.original() : res.resolution}</span>
<span className="pl-5 text-xs text-muted-foreground">
{res.width}x{res.height}
</span>
</DropdownMenuItem>
))}
{resolutions.map((res) => {
const itemKey = `${res.resolution}-${res.hdr ? 'hdr' : 'sdr'}`
const isSelected =
state.currentResolution === res.resolution &&
Boolean(state.isCurrentHdr) === Boolean(res.hdr)
return (
<DropdownMenuItem
key={itemKey}
onClick={() => changeResolution(res)}
className={cn(
'flex w-full items-center justify-between',
isSelected ? 'text-primary font-medium' : 'text-foreground',
)}
>
<div className="flex items-center gap-1.5">
<span>{res.resolution === 'Original' ? m.original() : res.resolution}</span>
{res.hdr && (
<span className="px-1 py-0.2 rounded text-[10px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
{m.hdr()}
</span>
)}
</div>
<span className="pl-5 text-xs text-muted-foreground">
{res.width}x{res.height}
</span>
</DropdownMenuItem>
)
})}
</DropdownMenuContent>
</DropdownMenu>
)}
@@ -370,16 +389,26 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
{resolutions.map((res) => (
<DropdownMenuItem
key={res.resolution}
onClick={() => handleDownload(res.key ?? '')}
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
>
<span>{res.resolution}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
))}
{resolutions.map((res) => {
const itemKey = res.key || `${res.resolution}-${res.hdr ? 'hdr' : 'sdr'}`
return (
<DropdownMenuItem
key={itemKey}
onClick={() => handleDownload(res.key ?? '')}
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground cursor-pointer"
>
<div className="flex items-center gap-1.5">
<span>{res.resolution}</span>
{res.hdr && (
<span className="px-1 py-0.2 rounded text-[10px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
{m.hdr()}
</span>
)}
</div>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
)
})}
{data.media?.original?.key && (
<>
<DropdownMenuSeparator />
@@ -1,5 +1,5 @@
// @vitest-environment happy-dom
import { cleanup, render } from '@testing-library/react'
import { act, cleanup, render } from '@testing-library/react'
import React from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import VideoViewer from './video-viewer'
@@ -182,4 +182,191 @@ describe('VideoViewer', () => {
}),
)
})
it('auto-selects HDR proxy when display supports HDR (dynamic-range: high)', () => {
const originalMatchMedia = window.matchMedia
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
matches: query === '(dynamic-range: high)',
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
}))
const hdrVideo: AssetInfo = {
id: 'video-hdr',
name: 'video-hdr.mp4',
proxyType: 'video',
media: {
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
},
videoTranscodes: [
{
resolution: '1080p',
url: 'https://cdn.example.com/video-1080p.mp4',
width: 1920,
height: 1080,
hdr: false,
},
{
resolution: '1080p',
url: 'https://cdn.example.com/video-1080p-hdr.mp4',
width: 1920,
height: 1080,
hdr: true,
},
],
},
} as unknown as AssetInfo
render(<VideoViewer file={hdrVideo} />)
expect(videojsMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
sources: [
{
src: 'https://cdn.example.com/video-1080p-hdr.mp4',
type: 'video/mp4',
},
],
}),
)
window.matchMedia = originalMatchMedia
})
it('auto-selects SDR proxy when display does not support HDR', () => {
const originalMatchMedia = window.matchMedia
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
}))
const hdrVideo: AssetInfo = {
id: 'video-sdr-fallback',
name: 'video-sdr-fallback.mp4',
proxyType: 'video',
media: {
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
},
videoTranscodes: [
{
resolution: '1080p',
url: 'https://cdn.example.com/video-1080p.mp4',
width: 1920,
height: 1080,
hdr: false,
},
{
resolution: '1080p',
url: 'https://cdn.example.com/video-1080p-hdr.mp4',
width: 1920,
height: 1080,
hdr: true,
},
],
},
} as unknown as AssetInfo
render(<VideoViewer file={hdrVideo} />)
expect(videojsMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
sources: [
{
src: 'https://cdn.example.com/video-1080p.mp4',
type: 'video/mp4',
},
],
}),
)
window.matchMedia = originalMatchMedia
})
it('shows play button and darkened overlay initially, but never again after playing (even when paused or scrubbed back to start)', () => {
const listeners: Record<string, () => void> = {}
videojsMock.mockImplementation(() => ({
on: vi.fn((event: string, cb: () => void) => {
listeners[event] = cb
}),
volume: vi.fn(),
duration: vi.fn(() => 10),
currentTime: vi.fn(() => 0),
bufferedEnd: vi.fn(() => 0),
playbackRate: vi.fn(() => 1),
ready: vi.fn(),
dispose: vi.fn(),
isDisposed: vi.fn(() => false),
}))
const testVideo: AssetInfo = {
id: 'test-video-lifecycle',
name: 'test.mp4',
proxyType: 'video',
media: {
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
},
videoTranscodes: [
{
resolution: '1080p',
url: 'https://cdn.example.com/test-1080p.mp4',
width: 1920,
height: 1080,
},
],
},
} as unknown as AssetInfo
const { container } = render(<VideoViewer file={testVideo} />)
const videoArea = container.querySelector('[data-testid="video-area"]')
expect(videoArea).toBeTruthy()
// 1. Initially (before playing): play button & 20% black tint are present
expect(videoArea?.querySelector('.bg-black\\/20')).not.toBeNull()
// 2. Start playback
act(() => {
listeners['play']?.()
})
expect(videoArea?.querySelector('.bg-black\\/20')).toBeNull()
// 3. Pause video: overlay must NOT show again
act(() => {
listeners['pause']?.()
})
expect(videoArea?.querySelector('.bg-black\\/20')).toBeNull()
// 4. Drag seekbar / time back to 0: overlay must STILL NOT show
act(() => {
listeners['timeupdate']?.()
})
expect(videoArea?.querySelector('.bg-black\\/20')).toBeNull()
})
})
@@ -54,17 +54,30 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
// We use a container ref to manually append the video element
const videoContainerRef = useRef<HTMLDivElement>(null)
// Logic to select best resolution based on screen size
// Logic to select best resolution based on screen size and dynamic range
const getInitialResolution = (): DisplayTranscode | null => {
if (resolutions.length === 0) return null
if (typeof window === 'undefined') return resolutions[0]
const prefersHdr =
typeof window.matchMedia === 'function' &&
window.matchMedia('(dynamic-range: high)').matches
const hasHdr = resolutions.some((r) => r.hdr)
const hasSdr = resolutions.some((r) => !r.hdr)
let candidateResolutions = resolutions
if (prefersHdr && hasHdr) {
candidateResolutions = resolutions.filter((r) => r.hdr)
} else if (!prefersHdr && hasSdr) {
candidateResolutions = resolutions.filter((r) => !r.hdr)
}
// Use device pixel ratio for high DPI screens
const screenWidth = window.innerWidth * (window.devicePixelRatio || 1)
// 1. Sort by width ascending
const sortedResolutions = [...resolutions].sort((a, b) => {
const sortedResolutions = [...candidateResolutions].sort((a, b) => {
const wA = a.width ?? 0
const wB = b.width ?? 0
return wA - wB
@@ -93,7 +106,9 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
showFrames: false,
currentResolution: initialRes?.resolution ?? '',
currentSrc: initialRes?.url ?? '',
isCurrentHdr: initialRes?.hdr ?? false,
})
const [hasStartedPlaying, setHasStartedPlaying] = useState(false)
const containerRef = useRef<HTMLDivElement>(null)
const rootRef = useRef<HTMLDivElement>(null)
const controlsTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
@@ -110,6 +125,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
}
},
seekTo: (second: number) => {
setHasStartedPlaying(true)
if (localPlayerRef.current) {
localPlayerRef.current.currentTime(second)
}
@@ -140,11 +156,13 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
duration: data.media?.metadata?.duration || 0,
currentResolution: res?.resolution ?? '',
currentSrc: res?.url ?? '',
isCurrentHdr: res?.hdr ?? false,
}))
setHasManuallyZoomed(false)
setIsPlayerReady(false)
setBuffered(0)
lastProcessedStartTimeRef.current = null
setHasStartedPlaying(false)
}, [data.id, Boolean(initialRes?.url)])
const vidW = data.media?.metadata?.originalWidth || 1920
@@ -246,6 +264,14 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames, isAudio)
const handleSeekToFrame = useCallback(
(frame: number) => {
setHasStartedPlaying(true)
return seekToFrame(frame)
},
[seekToFrame],
)
const currentTime = currentFrame / frameRate
const duration = totalFrames / frameRate
const progress = duration > 0 ? (currentTime / duration) * 100 : 0
@@ -284,8 +310,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
const videoElement = document.createElement('video-js')
videoElement.classList.add('vjs-big-play-centered', '!h-full', '!w-full')
// Hide it, but keep it in DOM
videoElement.style.opacity = '0'
// Keep it in DOM, enable visible rendering
videoElement.style.pointerEvents = 'none'
// Append to our container
@@ -348,6 +373,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
player.on('play', () => {
setState((p) => ({ ...p, isPlaying: true }))
setHasStartedPlaying(true)
onPlay?.()
})
player.on('pause', () => {
@@ -413,6 +439,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
if (startTime !== lastProcessedStartTimeRef.current) {
lastProcessedStartTimeRef.current = startTime
const targetFrame = Math.floor(startTime * frameRate + 0.45)
setHasStartedPlaying(true)
seekToFrame(targetFrame)
}
}
@@ -600,6 +627,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
...prev,
currentResolution: res.resolution,
currentSrc: res.url,
isCurrentHdr: res.hdr ?? false,
}))
player.src({ type: 'video/mp4', src: res.url })
@@ -758,8 +786,31 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
data-vjs-player
data-testid="video-area"
>
{/* Hidden VideoJS container */}
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
{/* Native Video Layer (Hardware-accelerated, full HDR EDR) */}
{!isAudio && (
<div
className="absolute pointer-events-none"
style={{
left: 0,
top: 0,
width: vidW,
height: vidH,
transform: `translate(${pan.x}px, ${pan.y}px) scale(${scale})`,
transformOrigin: '0 0',
}}
>
<div
ref={videoContainerRef}
className="w-full h-full [&_.video-js]:!w-full [&_.video-js]:!h-full [&_video]:!w-full [&_video]:!h-full [&_video]:!block [&_video]:!object-contain"
/>
</div>
)}
{isAudio && (
<div
ref={videoContainerRef}
className="absolute inset-0 pointer-events-none opacity-0"
/>
)}
{isAudio ? (
<div className="flex flex-col items-center justify-center text-muted-foreground w-full h-full pointer-events-none select-none">
@@ -771,8 +822,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
/>
</div>
) : (
/* Drawing Canvas (Visible) */
videoHtmlEl &&
/* Drawing Canvas (Transparent Overlay for annotations) */
containerSize.width > 0 && (
<DrawingCanvas
width={containerSize.width}
@@ -781,7 +831,6 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
width: vidW,
height: vidH,
}}
videoElement={videoHtmlEl}
annotations={displayAnnotations}
scale={scale}
offset={pan}
@@ -798,10 +847,10 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
)
)}
{/* Big Play Button Overlay (when paused) */}
{!state.isPlaying && !isDrawing && (
<div className="absolute inset-0 flex items-center justify-center bg-black/20 pointer-events-none z-10">
<div className="w-20 h-20 bg-white/10 backdrop-blur-sm rounded-full flex items-center justify-center border-2 border-white/30 animate-pulse">
{/* Initial Big Play Button Overlay (shown only before playback starts) */}
{!hasStartedPlaying && !isDrawing && (
<div className="absolute inset-0 flex items-center justify-center bg-black/20 pointer-events-none z-10 transition-opacity duration-200">
<div className="w-20 h-20 bg-white/10 backdrop-blur-sm rounded-full flex items-center justify-center border-2 border-white/30">
<Play className="w-10 h-10 text-white ml-1 fill-white" />
</div>
</div>
@@ -830,7 +879,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
frameRate={frameRate}
totalFrames={totalFrames}
currentFrame={currentFrame}
seekToFrame={seekToFrame}
seekToFrame={handleSeekToFrame}
onMouseEnter={handleControlsMouseEnter}
onMouseLeave={handleControlsMouseLeave}
allowDownload={allowDownload}
@@ -856,7 +905,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
frameRate={frameRate}
totalFrames={totalFrames}
currentFrame={currentFrame}
seekToFrame={seekToFrame}
seekToFrame={handleSeekToFrame}
onMouseEnter={handleControlsMouseEnter}
onMouseLeave={handleControlsMouseLeave}
allowDownload={allowDownload}
+2
View File
@@ -265,6 +265,8 @@
"ffmpeg_threads_description": "Maximum number of CPU threads used by FFmpeg during transcoding. Set to 0 for Auto.",
"threads_auto": "Auto",
"threads_count": "{count} threads",
"hdr": "HDR",
"sdr": "SDR",
"notification_settings": "Notification Settings",
"notifications_description": "Configure your personal notification preferences for this team.",
+2
View File
@@ -265,6 +265,8 @@
"ffmpeg_threads_description": "FFmpeg 转码时使用的最大 CPU 线程数。设置为 0 表示自动。",
"threads_auto": "自动",
"threads_count": "{count} 线程",
"hdr": "HDR",
"sdr": "SDR",
"notification_settings": "通知设置",
"notifications_description": "配置您在此团队的个人通知偏好。",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/webui",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./index.html",
@@ -300,6 +300,7 @@ function FileViewPage() {
key: t.key,
width: t.width,
height: t.height,
hdr: t.hdr,
})),
},
versions: versionsDataList,
+1
View File
@@ -23,6 +23,7 @@ export interface TopNavProjectState {
key: string
width: number
height: number
hdr?: boolean
}>
}
versions?: Array<{
+1 -1
View File
@@ -1 +1 @@
export const APP_VERSION = '0.4.7'
export const APP_VERSION = '0.4.8'
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/workflow-core",
"version": "0.4.7",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+163
View File
@@ -0,0 +1,163 @@
import { describe, expect, it } from 'vitest'
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { join, resolve } from 'node:path'
import { tmpdir } from 'node:os'
import {
formatChangelogDate,
generateMdxChangelog,
parseChangelogReleases,
syncDocsChangelog,
} from './generate-docs-changelog'
describe('generate-docs-changelog', () => {
describe('formatChangelogDate', () => {
it('formats YYYY-MM-DD into Month D, YYYY', () => {
expect(formatChangelogDate('2026-09-19')).toBe('September 19, 2026')
expect(formatChangelogDate('2026-01-05')).toBe('January 5, 2026')
expect(formatChangelogDate('2025-12-31')).toBe('December 31, 2025')
})
it('returns empty string for undefined or empty date', () => {
expect(formatChangelogDate(undefined)).toBe('')
expect(formatChangelogDate('')).toBe('')
})
it('returns original string if format is not YYYY-MM-DD', () => {
expect(formatChangelogDate('September 2026')).toBe('September 2026')
})
})
describe('parseChangelogReleases', () => {
const sampleChangelog = `# Changelog
All notable changes documented here.
## [Unreleased]
### Added
- In progress feature
## [0.4.7] - 2026-09-19
### Added
- Feature 1
- Feature 2
### Fixed
- Bug 1
## [0.4.6] - 2026-09-17
### Added
- Feature 3
## [0.0.1]
### Added
- Initial release
`
it('parses releases and skips [Unreleased]', () => {
const releases = parseChangelogReleases(sampleChangelog)
expect(releases).toHaveLength(3)
expect(releases[0]).toEqual({
version: '0.4.7',
date: '2026-09-19',
content: '### Added\n- Feature 1\n- Feature 2\n\n### Fixed\n- Bug 1',
})
expect(releases[1]).toEqual({
version: '0.4.6',
date: '2026-09-17',
content: '### Added\n- Feature 3',
})
expect(releases[2]).toEqual({
version: '0.0.1',
date: undefined,
content: '### Added\n- Initial release',
})
})
it('returns empty array for empty changelog', () => {
expect(parseChangelogReleases('')).toEqual([])
})
})
describe('generateMdxChangelog', () => {
it('generates valid Mintlify MDX with <Update> tags', () => {
const releases = [
{
version: '0.4.7',
date: '2026-09-19',
content: '### Added\n- Feature A',
},
{
version: '0.4.6',
content: '### Fixed\n- Bug B',
},
]
const mdx = generateMdxChangelog(releases)
expect(mdx).toContain('title: "Changelog"')
expect(mdx).toContain(
'description: "Recent updates, new features, and improvements in Shumai"',
)
expect(mdx).toContain('<Update label="v0.4.7" description="September 19, 2026">')
expect(mdx).toContain('### Added\n- Feature A')
expect(mdx).toContain('<Update label="v0.4.6">')
expect(mdx).toContain('### Fixed\n- Bug B')
expect(mdx).toContain('</Update>')
})
})
describe('syncDocsChangelog', () => {
const tempDir = join(tmpdir(), `test-sync-docs-changelog-${Date.now()}`)
const changelogPath = join(tempDir, 'CHANGELOG.md')
const outputPath = join(tempDir, 'changelog.mdx')
it('generates MDX and supports check mode', () => {
const sample = `## [0.1.0] - 2026-01-01\n\n- First version`
// Create temp dir
mkdirSync(tempDir, { recursive: true })
writeFileSync(changelogPath, sample, 'utf-8')
// Check before generating should return false
expect(syncDocsChangelog({ changelogPath, outputPath, check: true })).toBe(false)
// Sync should generate output
syncDocsChangelog({ changelogPath, outputPath })
expect(existsSync(outputPath)).toBe(true)
const content = readFileSync(outputPath, 'utf-8')
expect(content).toContain('<Update label="v0.1.0" description="January 1, 2026">')
// Check after generating should return true
expect(syncDocsChangelog({ changelogPath, outputPath, check: true })).toBe(true)
// Clean up
rmSync(tempDir, { recursive: true, force: true })
})
})
describe('Integration with repository CHANGELOG.md', () => {
it('successfully parses the actual repository CHANGELOG.md', () => {
const changelogPath = resolve(__dirname, '../CHANGELOG.md')
const content = readFileSync(changelogPath, 'utf-8')
const releases = parseChangelogReleases(content)
expect(releases.length).toBeGreaterThan(40)
const release047 = releases.find((r) => r.version === '0.4.7')
expect(release047).toBeDefined()
expect(release047?.date).toBe('2026-09-19')
expect(release047?.content).toContain('Introduce Keep a Changelog support')
const mdx = generateMdxChangelog(releases)
expect(mdx).toContain('<Update label="v0.4.7" description="September 19, 2026">')
expect(mdx).toContain('<Update label="v0.0.1" description="June 12, 2026">')
})
})
})
+200
View File
@@ -0,0 +1,200 @@
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
export interface ChangelogRelease {
version: string
date?: string
content: string
}
/**
* Formats an ISO date string (YYYY-MM-DD) into a human-readable string (Month D, YYYY).
* Returns the original string if parsing fails.
*/
export function formatChangelogDate(dateStr?: string): string {
if (!dateStr) {
return ''
}
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dateStr.trim())
if (!match) {
return dateStr.trim()
}
const year = parseInt(match[1], 10)
const monthIndex = parseInt(match[2], 10) - 1
const day = parseInt(match[3], 10)
const date = new Date(Date.UTC(year, monthIndex, day))
return date.toLocaleDateString('en-US', {
month: 'long',
day: 'numeric',
year: 'numeric',
timeZone: 'UTC',
})
}
/**
* Parses all released versions from a Keep a Changelog markdown string.
* Skips the ## [Unreleased] section.
*/
export function parseChangelogReleases(changelogContent: string): ChangelogRelease[] {
if (!changelogContent) {
return []
}
const releases: ChangelogRelease[] = []
// Matches "## [0.4.7] - 2026-09-19" or "## [v0.4.7]" or "## [Unreleased]"
const headerRegex = /^## \[(?:v)?([^\]]+)\](?:\s*-\s*([^\n\r]+))?$/gm
const matches: Array<{ version: string; date?: string; index: number; length: number }> = []
let match: RegExpExecArray | null
while ((match = headerRegex.exec(changelogContent)) !== null) {
matches.push({
version: match[1].trim(),
date: match[2]?.trim(),
index: match.index,
length: match[0].length,
})
}
for (let i = 0; i < matches.length; i++) {
const current = matches[i]
if (current.version.toLowerCase() === 'unreleased') {
continue
}
const startIndex = current.index + current.length
const endIndex = i + 1 < matches.length ? matches[i + 1].index : changelogContent.length
const content = changelogContent.slice(startIndex, endIndex).trim()
releases.push({
version: current.version,
date: current.date,
content,
})
}
return releases
}
/**
* Generates the MDX content for docs/changelog.mdx using Mintlify's <Update> component.
*/
export function generateMdxChangelog(releases: ChangelogRelease[]): string {
const lines: string[] = [
'---',
'title: "Changelog"',
'description: "Recent updates, new features, and improvements in Shumai"',
'---',
'',
]
for (const release of releases) {
const cleanVersion = release.version.replace(/^v/i, '')
const label = `v${cleanVersion}`
const formattedDate = formatChangelogDate(release.date)
const descAttr = formattedDate ? ` description="${formattedDate}"` : ''
lines.push(`<Update label="${label}"${descAttr}>`)
lines.push('')
if (release.content) {
lines.push(release.content)
lines.push('')
}
lines.push('</Update>')
lines.push('')
}
return lines.join('\n')
}
export interface SyncOptions {
changelogPath?: string
outputPath?: string
check?: boolean
}
/**
* Synchronizes docs/changelog.mdx with CHANGELOG.md.
* If check is true, returns whether the output file already matches the generated content.
*/
export function syncDocsChangelog(options: SyncOptions = {}): boolean {
const changelogPath = resolve(options.changelogPath ?? 'CHANGELOG.md')
const outputPath = resolve(options.outputPath ?? 'docs/changelog.mdx')
if (!existsSync(changelogPath)) {
throw new Error(`Changelog not found at ${changelogPath}`)
}
const changelogContent = readFileSync(changelogPath, 'utf-8')
const releases = parseChangelogReleases(changelogContent)
const mdxContent = generateMdxChangelog(releases)
if (options.check) {
if (!existsSync(outputPath)) {
return false
}
const currentMdx = readFileSync(outputPath, 'utf-8')
return currentMdx === mdxContent
}
writeFileSync(outputPath, mdxContent, 'utf-8')
return true
}
function parseCliArgs(args: string[]): {
check: boolean
changelogPath?: string
outputPath?: string
} {
let check = false
let changelogPath: string | undefined
let outputPath: string | undefined
for (let i = 0; i < args.length; i++) {
const arg = args[i]
if (arg === '--check') {
check = true
} else if (arg === '--changelog' || arg === '-c') {
changelogPath = args[++i]
} else if (arg === '--output' || arg === '-o') {
outputPath = args[++i]
}
}
return { check, changelogPath, outputPath }
}
export function runCli(argv: string[]): void {
const { check, changelogPath, outputPath } = parseCliArgs(argv)
try {
const targetOut = outputPath ?? 'docs/changelog.mdx'
if (check) {
const isUpToDate = syncDocsChangelog({ changelogPath, outputPath, check: true })
if (!isUpToDate) {
console.error(
`Error: ${targetOut} is out of date with changelog. Run: bun run docs:changelog`,
)
process.exit(1)
}
console.log(`✓ ${targetOut} is up to date.`)
} else {
syncDocsChangelog({ changelogPath, outputPath })
console.log(`✓ Generated ${targetOut} successfully.`)
}
} catch (error) {
console.error('Failed to sync docs changelog:', error)
process.exit(1)
}
}
const isDirectlyExecuted =
Boolean(import.meta.main) ||
(process.argv[1] ? resolve(process.argv[1]) === resolve(import.meta.filename ?? '') : false)
if (isDirectlyExecuted) {
runCli(process.argv.slice(2))
}
+8
View File
@@ -1,6 +1,7 @@
import { execSync } from 'node:child_process'
import { readFileSync, writeFileSync, readdirSync, existsSync } from 'node:fs'
import { join } from 'node:path'
import { syncDocsChangelog } from './generate-docs-changelog'
const releaseTarget = process.argv[2]
const bumpTypes = new Set(['major', 'minor', 'patch'])
@@ -136,6 +137,13 @@ function updateChangelog(newVersion: string) {
const updatedContent = content.replace(unreleasedRegex, replacement)
writeFileSync(changelogFile, updatedContent, 'utf-8')
console.log(` Updated ${changelogFile} for v${newVersion} (${dateStr})`)
try {
syncDocsChangelog()
console.log(' Updated docs/changelog.mdx')
} catch (error) {
console.warn(' Warning: Failed to update docs/changelog.mdx:', error)
}
}
function shellQuote(value: string) {