Back to the blog

SubtitleGenerator editorial

Our canvas credits roll stuttered. The fix was whole pixels.

Our in-browser rolling credits moved 8.19 px per frame. In our Chrome tests the text landed on whole pixel rows anyway, so the roll moved 8, 8, 8, 8, 9. What we measured, how we now pick an integer step, how we test it, and what the fix did not change.

Yana Li Updated November 26, 2026

Disclosure: I build SubtitleGenerator, which includes the free rolling credits maker this post is about. I used AI to help draft this post, write the measurement scripts and fact-check the text against our code. The code excerpts come from the November 5, 2026 fix commit (24222c921); the measurements were run for this post on November 25, 2026.

TL;DR: Our credits maker draws a scrolling roll on a <canvas> and encodes it to MP4 in the browser. The first version moved the text 8.19 px per frame. In the Chrome builds and fonts I tested, the browser did not draw text at 8.19 px offsets: it put the glyphs on whole pixel rows, so the roll actually moved 8, 8, 8, 8, 9, which shows up as a small hitch roughly five times a second. The fix was to choose a whole-number step, make the total distance an exact multiple of it, and round every coordinate. We also asked the encoder for more bits; re-measuring for this post showed that part did much less than we thought.

What the credits maker does

You type one credit per line (Directed by | Alex Chen), pick a look and a speed, and the page draws the roll on a canvas, 1280×720 for widescreen or 720×1280 for vertical. When you download, the same drawing function paints each frame, WebCodecs VideoEncoder encodes it as H.264 at 24 fps, and mp4-muxer writes the MP4. Nothing is uploaded.

The length of a roll comes from the number of lines: 3 seconds plus 1.2 seconds per line at normal speed, rounded, with a 6-second floor. The 6-line sample is 10 seconds, so 240 frames.

The first version: progress times distance

The first version treated the roll like any animation: a progress value from 0 to 1, times the distance the text has to travel.

// Before (simplified): every position is a fraction of the total travel
const block = frameHeight * 0.22;       // height reserved for one credit
const gap = frameHeight * 0.08;         // space between credits
const totalHeight = count * (block + gap) - gap;
const travel = frameHeight + totalHeight; // from below the frame to above it

const progress = frameIndex / (frameCount - 1);
const top = frameHeight - progress * travel + lineIndex * (block + gap);
ctx.fillText(name, width / 2, top + block / 2);

For the sample at 720 px tall, block is 158.4, gap is 57.6 and travel is 1958.4 px. Spread over 239 steps, that is 8.194 px per frame. Nothing in that code is wrong as arithmetic. Every frame is exactly 8.194 px further along.

On screen, the roll did not look like that. Text seemed to catch, as if a frame were being dropped every so often.

What the browser actually drew

I had assumed the problem was anti-aliasing: a glyph drawn at y = 16.39 gets its edges smeared across two pixel rows, a slightly different smear every frame. That is true for shapes. When I moved a fillRect by 8.194 px per frame for 24 frames, all 24 frames had different edge pixels, even after lining each one up to its nearest whole pixel. At an 8 px step, all 24 were identical.

Text behaved differently. In Playwright's headless Chromium 151 and in Chrome 158, both on a Mac, with the fonts I tried (Helvetica Neue and Arial), fillText at a fractional y came out as the same glyph bitmap placed on a whole pixel row. The browser was rounding the vertical position for me. That is an observation for these builds and settings, not a documented rule, so check your own target. So the fractional speed did not come out as a smooth 8.194 px; it came out as a mix of whole steps.

You can see this in your own browser. This snippet draws one line of text at a steadily rising y, finds the pixel row where its top edge lands, and counts how far it moved between frames:

// Draw one line of text at a steadily rising y, and record which pixel row
// its top edge actually lands on in each frame.
function measureSteps(stepPx, frames = 240) {
  const canvas = new OffscreenCanvas(400, 2400);
  const ctx = canvas.getContext('2d', { willReadFrequently: true });
  ctx.font = '600 35px Arial, sans-serif';
  ctx.textAlign = 'center';
  ctx.textBaseline = 'middle';
  const tops = [];
  for (let i = 0; i < frames; i++) {
    ctx.fillStyle = '#000';
    ctx.fillRect(0, 0, 400, 2400);
    ctx.fillStyle = '#fff';
    ctx.fillText('Alex Chen', 200, 2200 - i * stepPx);
    const { data } = ctx.getImageData(150, 0, 100, 2400);
    let top = -1;
    for (let p = 0; p < data.length; p += 4) {
      if (data[p] > 0) { top = Math.floor(p / 4 / 100); break; }
    }
    tops.push(top);
  }
  // How many frames moved by each whole number of pixels
  const moves = {};
  for (let i = 1; i < tops.length; i++) {
    const d = tops[i - 1] - tops[i];
    moves[d] = (moves[d] || 0) + 1;
  }
  return moves;
}

console.log('fractional', measureSteps(1958.4 / 239), 'integer', measureSteps(8));

In both browser builds I tested, it printed:

fractional {8: 192, 9: 47}  integer {8: 239}

So the old roll moved 8 px on 192 frames and 9 px on 47. The 9s arrive about every five frames, which at 24 fps is about five times a second. Your eye tracks scrolling text as if it moved at a constant speed, so every 9 is a small jump. That was the "catch".

I did not test Firefox or Safari for this post. A renderer that anti-aliases text at fractional positions, the way Chromium does with shapes, would give you the other problem instead: steady motion with edges that change every frame. Either way, the fix is the same.

The fix: choose the step first

If every frame has to move a whole number of pixels, the question changes from "what fraction of the distance is this frame?" to "what step, and what distance, divide evenly into the frames we have?"

The new rollMotion function works backwards from the frame count. It rounds the block height to a whole pixel, picks the integer step closest to the ideal speed, and then searches a small range of gaps between lines (from 24 px tighter to 8 px looser than the default) and steps around that ideal, so that the total distance is an exact multiple of the step and still fits in the frames. Here is the core of it, slightly simplified:

const slots = frameCount - 1;                    // number of moves between frames
const block = Math.round(height * 0.22);
const gapBase = Math.round(height * 0.08);
const nominal = height + count * block + (count - 1) * gapBase;
const idealStep = Math.max(1, Math.round(nominal / slots));

for (let gap = gapBase - 24; gap <= gapBase + 8; gap += 1) {
  const base = height + count * block + (count - 1) * gap;
  for (let step = idealStep - 1; step <= idealStep + 3; step += 1) {
    if (Math.ceil(base / step) > slots) continue; // would not finish in time
    const pad = (step - (base % step)) % step;    // round travel up to a multiple
    const travel = base + pad;
    const scrollSteps = travel / step;
    const hold = frameCount - (scrollSteps + 1);   // frames left after the roll
    const score =
      Math.abs(step - idealStep) * 100_000 +        // stay near the chosen speed
      hold * 10 +                                    // dead frames at the end
      Math.abs(gap - gapBase) * 100 +                // 1 px of gap = 10 held frames
      pad;
    // keep the lowest score
  }
}

The score is a weighted sum. It heavily penalizes moving away from the rounded ideal step, though a larger step is sometimes the only way to finish in time (a single line at 720p and normal speed needs 7 px, not the rounded 6). Among the remaining candidates, spacing, trailing hold frames and padding trade off against each other, and one pixel of gap change costs as much as ten held frames. The frame count itself never changes, so the file keeps the nominal duration the page shows.

Then every position is a whole number:

export function scrollOffset(frameIndex: number, motion: RollMotion): number {
  const index = Math.min(Math.max(0, Math.floor(frameIndex)), motion.frameCount - 1);
  return Math.min(index, motion.scrollSteps) * motion.step;
}

const top = Math.round(frameHeight) - scrollOffset(frameIndex, motion) + lineIndex * motion.stride;
const centerY = top + Math.round(block / 2);
// ...and the text helper rounds whatever it is given
ctx.fillText(text, Math.round(x), Math.round(y));

For the 6-line sample in 16:9, this picks an 8 px step, tightens the gap from 58 to 48 px and lands the travel at 1912 px, exactly 239 × 8. In 9:16 it picks 15 px per frame, keeps the gap at 102 px, and the last 6 frames hold after the roll has left the screen.

Two smaller changes came with it:

  • The preview uses the same frames. It used to compute a continuous progress on every requestAnimationFrame, so what you watched was not what you downloaded. Now it turns elapsed time into a 24 fps frame index and draws that exact frame.
  • The role line got bigger. Small uppercase role names were the first thing to become hard to read while moving. At 720p the role font went from 20 px to 26 px (2.8% to 3.6% of the frame height).

The encoder part, re-measured

The same commit changed the encoder settings. The first version tried H.264 Baseline first at 2 Mbps; the fix tries High profile first and asks for a constant 6 Mbps with latencyMode: 'quality', falling back to the same codecs without those two options if the browser refuses. The note we wrote at the time said Baseline had written about 176 kb/s.

For this post I re-ran the encode of the 10-second sample, old and new drawing against old and new settings. The table is the encoded H.264 video bitrate: the total bytes of the encoder's output chunks divided by the nominal 10 seconds, without MP4 overhead or audio.

DrawingEncoder settingsChromium 151Chrome 158
fractional (old)Baseline, 2 Mbps (old)182 kb/s176 kb/s
whole pixels (new)Baseline, 2 Mbps (old)167 kb/s155 kb/s
fractional (old)High, constant 6 Mbps (new)181 kb/s144 kb/s
whole pixels (new)High, constant 6 Mbps (new)165 kb/s126 kb/s

Both browsers accepted bitrateMode: 'constant' (isConfigSupported returned it in the resolved config), and both wrote far less than 6 Mbps. A black frame with a few lines of text moving in a straight line is easy to compress, and the encoder is free to treat the bitrate as a target, not a promise. So on this Mac, the bitrate change did not do what its name says. I have not checked whether it behaves differently on Windows or Android hardware encoders.

One pattern held in every pair: the new renderer produced 8 to 13% fewer encoded bytes than the old one under the same settings. That comparison changes more than the motion (the role font is larger, the spacing and travel differ, every coordinate is rounded), so it does not isolate the effect of integer steps, and I did not inspect motion vectors.

I also tried a quick PSNR-style comparison of decoded frames against the source, and it did not give me a measure I trust for text, so I am not making a quality claim from it. The improvement I can stand behind is the motion one.

How it is tested

The tests run in Vitest without a browser, so they check the arithmetic and the drawing calls, not the pixels:

  • Every move is the same. For 1, 6 and 120 lines, at 720 and 1280 px tall, at all three speeds (18 cases), every frame-to-frame offset during the scrolling phase equals step (any frames after that hold at the final offset), the travel is a multiple of the step, the first line starts exactly at the bottom edge, the last line has fully left by the final frame, and the frame count equals the advertised one.
  • The sample does not mix 8 and 9. A dedicated case for the 6-line sample at 720p asserts that the set of moves has exactly one value.
  • Every fillText gets whole numbers. A fake 2D context records each call. The test draws two consecutive frames, checks that every text coordinate in the first one is an integer, and checks that a name moved by exactly step in the next. It also checks the role and name font sizes.
  • Encoder order. The first candidate is High profile with constant 6 Mbps; Baseline comes later; the constant-bitrate variants come before the plain fallbacks.

What these tests do not cover: they never rasterize anything, so they would not catch a browser that anti-aliases or rounds differently, and they say nothing about what the encoder actually writes. The browser measurements in this post were run by hand for the post; they are not in CI.

Limits

  • The on-screen preview is still scaled. The canvas is 1280×720 internally, but CSS shrinks it to fit the page, so an 8 px step in canvas pixels is not a whole number of screen pixels. The preview is smoother than before, but the exported file is where the whole-pixel guarantee holds.
  • 24 fps on a 60 Hz screen. The preview advances one 24 fps frame at a time, which means each frame stays up for two or three display refreshes. That uneven cadence is a property of showing 24 fps on 60 Hz, not something this fix addresses.
  • Spacing changes with length and speed. To make the distance divide evenly, the gap between credits can shrink by up to 24 px or grow by up to 8 px. In the sample it shrank by 10 px. A user comparing two speeds side by side could notice.
  • Not tested: Firefox and Safari rendering, Windows and Android encoders, and anything about the roll after it is appended to a user's own video. Both append paths use the same drawing function; the streaming path has its own encoder settings, and the compatibility path reuses the standalone export settings.

The lesson

"Moves at 8.19 px per frame" was a correct description of our code and a wrong description of the video. Between the number you pass to fillText and the pixels that end up in a frame, something decides where things land, and for text in the Chrome builds I tested, that something rounded. If motion has to look steady, choose the step yourself, in whole pixels, and build the layout around it.

The same goes for encoder settings: the config you pass is a request. Measure what the encoder actually writes.

If you have built scrolling text on canvas, did you hit the same 8-and-9 pattern, or did your browser blur it instead?

Frequently asked questions

Why does scrolling text on an HTML canvas stutter even at a steady frame rate?

If each frame moves the text by a fractional number of pixels, the browser has to put it somewhere on the pixel grid. In our tests in headless Chromium 151 and Chrome 158 on a Mac, with the fonts we tried, fillText landed on whole pixel rows, so a speed of 8.19 px per frame came out as 8 px on 192 frames and 9 px on 47 frames. That uneven step reads as a hitch several times a second.

How do you make a canvas roll move smoothly?

Pick a whole-number step per frame, make the total distance an exact multiple of that step, and round every coordinate you pass to the canvas. If the distance does not divide evenly, adjust the layout (we nudge the gap between lines) or hold the last frames, rather than letting the step vary.

Does asking WebCodecs for a higher bitrate make text sharper?

Not reliably. We ask the H.264 encoder for a constant 6 Mbps, and Chrome accepts the setting, but on the Mac we re-tested, the encoded video for the 10-second sample roll still came out at roughly 125 to 165 kb/s. Treat bitrate settings as a request and measure the encoded output.

Put the workflow on a video

Inspect a local file or open the built-in sample to preview caption styles and export formats. Your video stays on your device.

Upload your video