fix(canvas): size video nodes to the video's real aspect ratio - #106
Open
Luna Qiu (lunaqiu) wants to merge 1 commit into
Open
fix(canvas): size video nodes to the video's real aspect ratio#106Luna Qiu (lunaqiu) wants to merge 1 commit into
Luna Qiu (lunaqiu) wants to merge 1 commit into
Conversation
Dragging or pasting a video created the node at the generic 400x300 (4:3) default: the drop/paste builder uploaded the file without measuring it, so `naturalDimensions` was absent and `resolveAddNodes` fell back to the type default. A 720x1280 clip rendered letterboxed inside a 4:3 box. Add `getVideoDimensionsFromBlob` alongside `getImageDimensionsFromBlob` and call it from the video branch of `uploadFileToNodeInput`. `CanvasToolbar` now reuses the shared helpers instead of its private copies. Probing is non-fatal: a codec the browser cannot decode (e.g. ProRes .mov) still yields a node at the default size, where previously the rejected probe propagated through `Promise.all` and dropped the node entirely. Fixes microsoft#105
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes are targeted, match the stated problem/solution, and the remaining feedback is a small documentation/intent clarity nit.
Pull request overview
This PR fixes incorrect default sizing for newly added video nodes on the canvas by measuring the video’s intrinsic dimensions at ingest time and passing them through as naturalDimensions, allowing existing sizing logic to preserve the real aspect ratio instead of falling back to the generic 4:3 default.
Changes:
- Added
getVideoDimensionsFromBlobto measure video intrinsic dimensions via metadata preload and revoke object URLs on success/error. - Updated
uploadFileToNodeInputto probe video dimensions in parallel with upload and attachnaturalDimensions(non-fatal on probe failure). - Removed toolbar-local media probing helpers and reused the shared blob-dimension helpers for image/video uploads.
File summaries
| File | Description |
|---|---|
| apps/web/src/utils/io/media.ts | Adds a shared video-dimension probe helper mirroring the existing image probe. |
| apps/web/src/handler/canvasCommand/nodeInputBuilders.ts | Ensures drag/drop + paste video inputs include naturalDimensions when available. |
| apps/web/src/components/Panels/Canvas/CanvasToolbar.tsx | Reuses shared media probing utilities and makes probe failures non-fatal for uploads. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
250
to
254
| if (type === 'image') { | ||
| const [uploadedUrl, dims] = await Promise.all([ | ||
| uploadImage(file, canvasId), | ||
| getImageDimensions(file), | ||
| getImageDimensionsFromBlob(file).catch(() => undefined), | ||
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #105
Problem
Dragging or pasting a video onto the canvas created the node at the generic 400×300 (4:3) default, so a 720×1280 clip rendered letterboxed with large empty bars.
uploadFileToNodeInputuploaded the file without measuring it, sonaturalDimensionswas absent andresolveAddNodesfell back to thevideotype default. The image branch directly above already measured viagetImageDimensionsFromBlob; the only code that ever probed a video was a privategetVideoDimensionsinsideCanvasToolbar.tsx.The wrong ratio was sticky:
resolveGeometryEditpreserves the current box ratio for image/video, so every later resize faithfully preserved the incorrect 4:3.Change
utils/io/media.ts— addgetVideoDimensionsFromBlob, mirroringgetImageDimensionsFromBlob(preload='metadata', revokes the object URL on both paths).nodeInputBuilders.ts— the video branch now measures alongside the upload and passesnaturalDimensions.CanvasToolbar.tsx— drops its two private probes and reuses the shared helpers.Probing is non-fatal. A codec the browser cannot decode (e.g. ProRes
.mov) still yields a node at the default size; previously the rejected probe propagated throughPromise.alland the toolbar path dropped the node entirely.Not covered
Agent-created video nodes hit the same default — the aspect-ratio normalizers in
apps/server/src/modules/canvas/canvas-executor.tsare all gated onnodeType === 'image'. Left out deliberately: there is no video-generation tool, so an agent can only point at a pre-existing video artifact, and correcting it server-side would need an MP4/WebM metadata parser. Existing mis-sized nodes are not corrected retroactively; re-adding the file fixes them.Verification
.mp4→ node is 400×711 instead of 400×300.pnpm typecheckclean;pnpm lint0 errors; web unit tests 44 passing.