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
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.