cd /news/developer-tools/converting-16-9-video-to-9-16-the-ma… · home › topics › developer-tools › article
[ARTICLE · art-178936] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Converting 16:9 video to 9:16: the math behind crop, letterbox and blur-fill

A developer at browser-based video studio Skrrol AI published the arithmetic behind converting 16:9 footage to 9:16, showing that a full-height vertical crop of a 1920×1080 source retains only a 608-pixel-wide window — 31.7% of the picture. The writeup provides two small JavaScript functions, cropWindow and letterbox, that compute a focus-point-driven crop or a centered fit, and notes that blur-fill combines both at the cost of an extra full-frame draw and blur per frame.

key takeaway

A 1920×1080 source cropped to a full-height 9:16 window keeps only 608 pixels of width — 31.7% of the frame — so animate the focus point rather than defaulting to a centered crop.

by read4 min views1 publishedNov 30, 2026

Every horizontal video eventually has to become a vertical one. YouTube wants 16:9; Shorts, Reels and TikTok want 9:16. There are only three honest ways to make that conversion, and each one is a few lines of arithmetic. This post walks through the numbers and gives you two small functions that compute them.

Disclosure: I work on Skrrol AI, a browser-based video studio. The math below is tool-independent.

Take a 1920×1080 source and a 1080×1920 target.

The target's aspect ratio is 9 ÷ 16 = 0.5625. The tallest 9:16 window that fits inside a 1080-pixel-high frame is 1080 × 0.5625 = 607.5, so about 608 pixels wide.

608 out of 1920 is 31.7% of the picture. A full-height vertical crop throws away more than two thirds of what you shot. That one number explains why naive conversions look bad: the subject only has to drift a little off-centre to leave the frame.

Cut a 608×1080 window out of the source and scale it up to 1080×1920. The picture fills the screen, but:

The only real decision is where the window sits. Centre is the default, but a window that follows the subject is nearly always better. Here is a function that takes a focus point (0 to 1 across the frame) and returns a window that never leaves the source:

// Largest window of the target aspect that fits inside the source.
function cropWindow(srcW, srcH, targetW, targetH, focusX = 0.5, focusY = 0.5) {
  const targetAspect = targetW / targetH;
  const srcAspect = srcW / srcH;
  let w, h;
  if (srcAspect > targetAspect) {
    h = srcH;
    w = Math.round(srcH * targetAspect);
  } else {
    w = srcW;
    h = Math.round(srcW / targetAspect);
  }
  const x = Math.round(Math.min(Math.max(focusX * srcW - w / 2, 0), srcW - w));
  const y = Math.round(Math.min(Math.max(focusY * srcH - h / 2, 0), srcH - h));
  return { x, y, w, h };
}

cropWindow(1920, 1080, 1080, 1920);
// { x: 656, y: 0, w: 608, h: 1080 }

cropWindow(1920, 1080, 1080, 1920, 0.3);
// { x: 272, y: 0, w: 608, h: 1080 }   subject left of centre

cropWindow(1920, 1080, 1080, 1920, 0);
// { x: 0, y: 0, w: 608, h: 1080 }     clamped to the left edge

With a canvas, the window maps straight onto drawImage:

const { x, y, w, h } = cropWindow(video.videoWidth, video.videoHeight, 1080, 1920, focusX);
ctx.drawImage(video, x, y, w, h, 0, 0, 1080, 1920);

Animate focusX over time and you have a reframe that follows the action.

Scale the whole frame down until it fits the target width and centre it.

// Whole source scaled to fit inside the target, centred.
function letterbox(srcW, srcH, targetW, targetH) {
  const scale = Math.min(targetW / srcW, targetH / srcH);
  const w = Math.round(srcW * scale);
  const h = Math.round(srcH * scale);
  return { x: Math.round((targetW - w) / 2), y: Math.round((targetH - h) / 2), w, h, scale };
}

letterbox(1920, 1080, 1080, 1920);
// { x: 0, y: 656, w: 1080, h: 608, scale: 0.5625 }

Nothing is lost, but the video is now a 1080×608 strip with a 656-pixel bar above and below. It occupies 31.7% of the screen: the same number as before, seen from the other side. Crop keeps a third of the picture at full size; letterbox keeps all of the picture at a third of the size.

Blur-fill is letterbox with the bars replaced: draw the frame once as a crop that fills the canvas, blur it heavily, then draw the letterboxed frame on top. It uses both functions above, one after the other. The viewer still sees the whole picture, and the empty space reads as intentional. It costs an extra full-frame draw and a blur per frame.

Scaling 1920×1080 directly to 1080×1920 squeezes the width to 56% and stretches the height to 178%. Every face and every circle is distorted. It is almost never what you want.

Situation Use
One subject, roughly centred, not moving much Crop, centre window
One subject that moves Crop with an animated focus point
Wide shot where the composition is the point Letterbox or blur-fill
Two subjects on opposite sides of the frame Letterbox, or cut between two crop windows
Text burned in across the full width Letterbox; a crop will cut the words

The same functions cover every target. For a 1920×1080 source:

Target Size Crop window Width kept
9:16 1080×1920 608×1080 31.7%
4:5 1080×1350 864×1080 45.0%
1:1 1080×1080 1080×1080 56.3%

Square and 4:5 are far more forgiving than 9:16, which is worth remembering when one master has to feed several platforms.

If you would rather not write the rendering yourself, Skrrol's aspect ratio converter runs in the browser, with project presets for 16:9, 9:16, 1:1, 4:5 and 21:9.

── more in #developer-tools 4 stories · sorted by recency
── more on @skrrol ai 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/converting-16-9-vide…] indexed:0 read:4min 2026-11-30 · —