cd /news/ai-products/why-our-mp4-validator-rejected-perfe… · home › topics › ai-products › article
[ARTICLE · art-173701] src=dev.to ↗ pub= topic=ai-products verified=true sentiment=↑ positive

Why our MP4 validator rejected perfectly good phone videos (and the 16.16 fixed-point detail behind it)

A developer building MakeAI Media, an AI image and video studio, fixed an MP4 validator that was rejecting valid phone videos because it read the track header's 16.16 fixed-point display dimensions as if they were integer pixel sizes. The validator now rounds the fixed-point values and falls back to the coded size in the first visual sample entry when the display size is invalid, and the client passes through the server's real error message instead of a generic format error.

recommendation

When validating uploaded media, parse tkhd dimensions as 16.16 fixed-point and fall back to stsd coded size, and surface the server's real error instead of a generic format message.

more in playbook: Verifying model output
by read1 min views1 publishedNov 21, 2026

We let users upload a short MP4 that drives an AI video job. Because the job is billed per second, the server never trusts the browser's duration: it parses the MP4 boxes itself (ftyp, moov, trak, mdhd, stts, stsz) and computes the real length before quoting a price.

Last week a user uploaded a normal vertical phone clip. The browser preview played fine, yet the server answered with a generic "use an MP4 between 3 and 30 seconds" error. Two bugs were stacked here.

1. The error message hid the real reason. The client caught every upload failure and showed the same format rule. Once we passed the server's message through, the actual cause appeared: Invalid MP4 dimensions.

2. We read display size as if it were pixel size. The width and height in the track header (tkhd) are 16.16 fixed-point numbers, and they describe the display size after the pixel aspect ratio is applied. Our validator required Number.isInteger(width). Phone encoders and anamorphic sources often store values such as 607.5, and some files store 0 there. Both were rejected.

The fix:

let width = Math.round(view.getUint32(tkhd.end - 8) / 65536);
let height = Math.round(view.getUint32(tkhd.end - 4) / 65536);
if (!validSize(width, height)) {
  // Fall back to the coded size in the first visual sample entry (stsd).
  // fullbox(4) + entry_count(4), then entry header(8) + 24 bytes.
  const entry = stsd.data + 8;
  width = view.getUint16(entry + 32);
  height = view.getUint16(entry + 34);
  if (!validSize(width, height)) throw new Error('Invalid MP4 dimensions');
}

Takeaways:

tkhd value; it costs two lines with a synthetic MP4 fixture. This runs in the upload path of MakeAI Media, an AI image and video studio I'm building. Drafted with AI assistance and checked against the actual code change.

── more in #ai-products 4 stories · sorted by recency
── more on @makeai media 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/why-our-mp4-validato…] indexed:0 read:1min 2026-11-21 · —