{"slug": "why-our-mp4-validator-rejected-perfectly-good-phone-videos-and-the-16-16-fixed", "title": "Why our MP4 validator rejected perfectly good phone videos (and the 16.16 fixed-point detail behind it)", "summary": "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.", "body_md": "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.\n\nLast 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.\n\n**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`.\n\n**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.\n\nThe fix:\n\n``` js\nlet width = Math.round(view.getUint32(tkhd.end - 8) / 65536);\nlet height = Math.round(view.getUint32(tkhd.end - 4) / 65536);\nif (!validSize(width, height)) {\n  // Fall back to the coded size in the first visual sample entry (stsd).\n  // fullbox(4) + entry_count(4), then entry header(8) + 24 bytes.\n  const entry = stsd.data + 8;\n  width = view.getUint16(entry + 32);\n  height = view.getUint16(entry + 34);\n  if (!validSize(width, height)) throw new Error('Invalid MP4 dimensions');\n}\n```\n\nTakeaways:\n\n`tkhd` value; it costs two lines with a synthetic MP4 fixture.\nThis runs in the upload path of [MakeAI Media](https://makeaimedia.com), an AI image and video studio I'm building. *Drafted with AI assistance and checked against the actual code change.*", "url": "https://wpnews.pro/news/why-our-mp4-validator-rejected-perfectly-good-phone-videos-and-the-16-16-fixed", "canonical_source": "https://dev.to/coderbuffer/why-our-mp4-validator-rejected-perfectly-good-phone-videos-and-the-1616-fixed-point-detail-behind-n7b", "published_at": "2026-11-21 08:32:28+00:00", "updated_at": "2026-11-21 08:42:04.481621+00:00", "lang": "en", "topics": ["ai-products", "ai-tools", "developer-tools"], "entities": ["MakeAI Media"], "also_reported_by": [], "takeaway": "MP4 tkhd width and height are 16.16 fixed-point display dimensions, not integers, so divide by 65536 and round, falling back to the stsd sample entry's coded size when the display size is invalid.", "recommendation": {"advice": "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.", "playbook": "output-verification", "playbook_url": "https://wpnews.pro/playbooks/output-verification"}, "alternates": {"html": "https://wpnews.pro/news/why-our-mp4-validator-rejected-perfectly-good-phone-videos-and-the-16-16-fixed", "markdown": "https://wpnews.pro/news/why-our-mp4-validator-rejected-perfectly-good-phone-videos-and-the-16-16-fixed.md", "text": "https://wpnews.pro/news/why-our-mp4-validator-rejected-perfectly-good-phone-videos-and-the-16-16-fixed.txt", "jsonld": "https://wpnews.pro/news/why-our-mp4-validator-rejected-perfectly-good-phone-videos-and-the-16-16-fixed.jsonld"}}